MSK Afridi

MSK Afridi

  • 1.9k
  • 44
  • 809

System.Data.SqlClient.SqlException . cant insert

Apr 4 2020 10:42 AM
Hello there,
 
I am a beginner to C# and trying to insert signup data in MSSQL. but getting System.Data.SqlClient.SqlException .in System.Data.dll. I have successfully inserted data in other pages but here I am facing this issue. code is as follows
  1. void SignUpNewMember()  
  2. {  
  3. try  
  4. {  
  5. SqlConnection con = new SqlConnection(strcon);  
  6. if (con.State == ConnectionState.Closed)  
  7. {  
  8. con.Open();  
  9. }  
  10. SqlCommand cmd = new SqlCommand("INSERT INTO member_master_tbl (full_name,dob,contact_no,email,state,city,pincode,full_address,member_id,password,account_status) values (@full_name,@dob,@contact_no,@email,@state,@city,@pincode,@full_address,@member_id,@password,@account_status)", con);  
  11. cmd.Parameters.AddWithValue("@full_name", TextBox1.Text.Trim());  
  12. cmd.Parameters.AddWithValue("@dob", TextBox2.Text.Trim());  
  13. cmd.Parameters.AddWithValue("@contact_no", TextBox3.Text.Trim());  
  14. cmd.Parameters.AddWithValue("@email", TextBox4.Text.Trim());  
  15. cmd.Parameters.AddWithValue("@state", DropDownList1.SelectedItem.Value);  
  16. cmd.Parameters.AddWithValue("@city", TextBox6.Text.Trim());  
  17. cmd.Parameters.AddWithValue("@pincode", TextBox7.Text.Trim());  
  18. cmd.Parameters.AddWithValue("@full_address", TextBox5.Text.Trim());  
  19. cmd.Parameters.AddWithValue("@member_id", TextBox8.Text.Trim());  
  20. cmd.Parameters.AddWithValue("@password", TextBox9.Text.Trim());  
  21. cmd.Parameters.AddWithValue("@account_status""pending");  
  22. cmd.ExecuteNonQuery();  
  23. con.Close();  
  24. Response.Write("<script>alert('Sign Up Successful. Go to User Login to Login');</script>");  
  25. }  
  26. catch (Exception ex)  
  27. {  
  28. Response.Write("<script>alert('" + ex.Message + "');</script>");  
  29. }  
  30. }  
plz guide what is wrong with this code as the same code is working on other pages
Regards

Answers (14)