我不知道这是为什么,基本上,当我使用以下函数插入一行时:
public bool CreateUser(string username, string password, string email, int age = 0)
{
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = "Data Source=localhost\\SQLEXPRESS;" +
"Initial Catalog=Pubs;Integrated Security=SSPI;Trusted_Connection=True;";
try
{
myConnection.Open();
string query = "INSERT INTO SiteUser VALUES('" + username + "', '" + password + "', '" + email + "', " + age + ")";
SqlCommand cmd = new SqlCommand(query);
cmd.Connection = myConnection;
cmd.ExecuteNonQuery();
myConnection.Close();
}
catch (Exception excep)
{
string error = excep.ToString();
Response.Write(error);
return false;
}
return true;
}
字段“password”最后会有空格(如“password”)。所以不管密码是什么,后面都是空格。
奇怪的是,“用户名”字段没有发生这种情况,两者都是char(50)类型。