我想通過匹配用戶名&密碼創建一個登錄帳戶。我想將結果保存在一個名爲result的局部變量中。當用戶登錄時,結果應該是1,但它總是返回-1。我的代碼如下......選擇查詢錯誤
protected void LoginBtn_Click(object sender, EventArgs e)
{
string Name = nameTextBox.Text;
string Password = passwordTextBox.Text;
nameTextBox.Text = "";
passwordTextBox.Text = "";
string connectionstring = @"Integrated Security=True;Initial Catalog=HMIS;Data Source=.\SQLEXPRESS";
SqlConnection connection = new SqlConnection(connectionstring);
connection.Open();
string selectquery = "Select ID from UsersInfo where UserName='" + @Name+ "' and Password='" + @Password + "'";
SqlCommand cmd = new SqlCommand(selectquery, connection);
cmd.Parameters.AddWithValue("@UserName", Name);
cmd.Parameters.AddWithValue("@Password", Password);
//object result = cmd.ExecuteNonQuery();
//if (result != null)
int result = (int)cmd.ExecuteNonQuery();
if (result > 0)
這段代碼有什麼好運? –