问题描述
- 求大神解答!c#+sqlserver简单的注册
-
string username = txtUserName.Text; string password = txtPwd.Text; string connconfig = ""server=127.0.0.1;Database=NetworkManagement;uid=sa;pwd=123456""; SqlConnection conn = new SqlConnection(connconfig); conn.Open(); string sql = ""select id from Administrator where username='"" + username + ""'""; string sql1 = ""insert into Administrator(usernamepassword) values ('"" + username + ""''"" + password + ""')""; SqlCommand comm = new SqlCommand(sql conn); SqlDataReader sdr = comm.ExecuteReader(); if (sdr[""id""]==null) { Session[""name""] = username; SqlCommand comm1 = new SqlCommand(sql1 conn); SqlDataReader sdr1 = comm1.ExecuteReader(); Response.Redirect(""default.aspx""); } else { Response.Redirect(""error.aspx""); } conn.Close();} 就是不行啊,怎么办啊 愁死我了
解决方案
if (sdr[""id""]==null) 改成 if (sdr.Read())
解决方案二:
打个断点调试一下就知道了
解决方案三:
先看看sql,sql1各自的执行结果。估计语句有问题。
时间: 2024-11-03 18:24:53