- 求大神解答!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(username,password) 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())