0
這裏是我的代碼在用戶插入數據庫的行動。 請讓我知道在哪裏應用try catch塊以防止在這種情況下發生任何類型的異常。在MVC 4中,何處應用控制器的動作?
if (ModelState.IsValid)
{
user.Type = 'J';
user.DateOfJoining = DateTime.Now;
using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnectionString"].ToString()))
{
using (SqlCommand command = new SqlCommand("SignupUser", connection))
{
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.AddWithValue("@FirstName",user.FirstName);
command.Parameters.AddWithValue("@LastName",user.LastName);
command.Parameters.AddWithValue("@Email",user.Email);
command.Parameters.AddWithValue("@Password",user.Password);
command.Parameters.AddWithValue("@Mobile",user.Mobile);
command.Parameters.AddWithValue("@City",user.City);
command.Parameters.AddWithValue("@StateProvince",user.StateProvince);
command.Parameters.AddWithValue("@Country",user.Country);
command.Parameters.AddWithValue("@Type",user.Type);
command.Parameters.AddWithValue("@DateOfJoining",user.DateOfJoining);
connection.Open();
int result = command.ExecuteNonQuery();
connection.Close();
return RedirectToAction("account");
}
}
}