数据库的表中没有刚注册的信息,怎么办??急求问,谢谢大家了!!!
初学C#.NET
一个注册的程序,程序运行是正常,注册完也会显示注册成功,可在数据库表中没有刚注册的用户信息,怎么办??
程序为
private void BT_submit_Click(object sender, System.EventArgs e)
{
string connstr= "server=127.0.0.1;database=aspnet;uid=sa;pwd=111 ";
string strsql= "select count(*)from UserInfo where UserID like ' "+TB_UserName.Text+ " ' ";
SqlConnection Conn=new SqlConnection(connstr);
SqlCommand mycommand=new SqlCommand(strsql,Conn);
Conn.Open();
int flag=(int)mycommand.ExecuteScalar();
Conn.Close();
if(flag==0)
{
string selectstr= "insert into UserInfo(UserID,Pwd,Sex,Email,Website)values( ' "+TB_UserName.Text+ " ', ' "+TB_Pwd.Text+ " ', ' "+RBL_Sex.SelectedItem.Value+ " ', ' "+TB_Email.Text+ " ', ' "+WebSite+ " ',getdate()) ";
SqlCommand addcommand=new SqlCommand(selectstr,Conn);
Conn.Open();
Conn.Close();
Session[ "username "]=TB_UserName.Text;
Session[ "Sex "]=RBL_Sex.SelectedItem.Value;
Label7.Text= "注册成功,请先登录! ";
}
else
{
Label7.Text= "对不起,该用户名已经存在,请选择其他用户名! ";
TB_UserName.Text= " ";
TB_Pwd.Text= " ";
TB_Pswd.Text= " ";
}
}
private void BT_reset_Click(object sender, System.EventArgs e)
{
Response.Redirect( "Register.aspx ");
}
[解决办法]
if(flag==0)
{
string selectstr= "insert into UserInfo(UserID,Pwd,Sex,Email,Website)values( ' "+TB_UserName.Text+ " ', ' "+TB_Pwd.Text+ " ', ' "+RBL_Sex.SelectedItem.Value+ " ', ' "+TB_Email.Text+ " ', ' "+WebSite+ " ',getdate()) ";
SqlCommand addcommand=new SqlCommand(selectstr,Conn);
Conn.Open();
addcommand..ExecuteNonQuery();
Conn.Close();
Session[ "username "]=TB_UserName.Text;
Session[ "Sex "]=RBL_Sex.SelectedItem.Value;
Label7.Text= "注册成功,请先登录! ";
}