我想做个注册页面,后台数据库为SQL,但是做完后执行没反应。。求助大大
protected void btnOK_Click(object sender, EventArgs e){
string ConnStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
SqlConnection conn = new SqlConnection(ConnStr);
SqlCommand Insert_UserInfo = new SqlCommand();
SqlCommand Insert_Pwd = new SqlCommand();
SqlCommand Uid_rd = new SqlCommand();
//SqlCommand Uid_wr = new SqlCommand();
Insert_UserInfo.Connection = conn;
Insert_Pwd.Connection = conn;
Uid_rd.Connection = conn;
//Uid_wr.Connection = conn;
try
{
conn.Open();
Insert_UserInfo.CommandText = "Insert into UserInfo(UserName,UserTel,UserDate,UserBrBookNo) Values ('" + this.txtUserName.Text.Trim() + "','" + this.txtUserTel.Text.Trim() + "','" + this.lbDataTime.Text + "','0')";//先在SQL中打入姓名,电话,日期,书号
Uid_rd.CommandText = "select UserId from UserInfo where UserName = '" + this.txtUserName.Text.Trim() + "'";//由于在SQL中UID是自动生成的,这时读出刚才注册的UID号
string Uid = Uid_rd.CommandText;
Insert_Pwd.CommandText = "Insert into UserPwd(UserId,UserPwd) Values(" + Uid + "," + this.txtUsrPwd1.Text.Trim() + ")";通过读出的UID账号和密码录入数据库
string url = "Login_Default2.aspx?Num = "+Uid+"";
Response.Redirect(url);页面传值
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{ conn.Close(); }
}
}
其中,我设置Uid为账号,在SQL中是自增账号,请问代码哪里有错误导致我SQL和程序没反应,我应该怎么改呢?
求助大大 --------------------编程问答-------------------- --------------------编程问答-------------------- 用户ID,电话之类的在一个表,用户名和密码在另一个表 --------------------编程问答-------------------- 求助啊。。。改了"Insert into UserPwd(UserId,UserPwd) Values('" + Uid + "','" + this.txtUsrPwd1.Text.Trim() + "')"后还是没反应,数据库没变化 --------------------编程问答-------------------- Uid 是数字类型的,不需要加引号。 --------------------编程问答--------------------
Insert_Pwd.CommandText = "Insert into UserPwd(UserId,UserPwd) Values(" + Uid + ",'" + this.txtUsrPwd1.Text.Trim() + "')";
你写的代码真够乱的
一次new那么多command。。。。。。
--------------------编程问答-------------------- 从SQL中读取的都是字符串啊 --------------------编程问答-------------------- --------------------编程问答--------------------
你说的Uid在两个表里面都是为自增账号么?按你这种设计的话,在UserPwd表里面的UserId不能设为自增哈
还有你后来修改加引号的那个 账号ID不需要加引号,密码需要加引号
--------------------编程问答--------------------
"Insert into UserPwd(UserId,UserPwd) Values(" + Uid + ",'" + this.txtUsrPwd1.Text.Trim() + "')"
当然,数据库操作参数化是最好的 --------------------编程问答--------------------
我调试下亲~ --------------------编程问答--------------------
多谢高手,回头好好学下~~ 多谢~
--------------------编程问答-------------------- LZ编码感觉好乱 好重复,, 看着挺烦的 --------------------编程问答-------------------- 没反应就是对了
有反应才是有问题
______
感觉我说的有问题??
因为我没找到您的方法返回值
就是说您走了一圈什么也没干
补充:.NET技术 , ASP.NET