string _connStr = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C: \Users\James JJ\Desktop\jj\Web App\Website\App_Data\LoginDB.mdf;Integrated Security=True";
string _query = "INSERT INTO [RegistrationTable] (Email, Password, HomeAddress, PostalCode, Gender) VALUES (@email, @password, @haddress, @postalcode, @gender)";
using (SqlConnection conn = new SqlConnection(_connStr))
{
using (SqlCommand comm = new SqlCommand())
{
comm.Connection = conn;
comm.CommandType = CommandType.Text;
comm.CommandText = _query;
comm.Parameters.AddWithValue("@email", Emailtxt.Text);
comm.Parameters.AddWithValue("@password", Passwordtxt.Text);
comm.Parameters.AddWithValue("@homeaddress", hAddresstxt.Text);
comm.Parameters.AddWithValue("@postalcode", Postaltxt.Text);
comm.Parameters.AddWithValue("@gender", gender);
conn.Open();
comm.ExecuteNonQuery();
Response.Redirect("RegistrationSuccess.aspx");
}
}
我确实在网上尝试了所有解决方案,但仍然不断出错。