Shiva Tiwari

Shiva Tiwari

  • NA
  • 73
  • 5.2k

cmd.ExecuteScalar() is not returning value

Jun 13 2020 3:02 AM
Recored is inserting but cmd.ExecuteScalar() is not returning any value

string query = "Insert into customer(FirstName,LastName,Email,Contact,House,street,colony,city,state,country,Added_on) values(@FirstName,@LastName,@Email,@Contact,@House,@street,@colony,@city,@state,@country,@Added_on)";
SqlCommand cmd = new SqlCommand(query, EcomConString);
cmd.Parameters.AddWithValue("@FirstName", SqlDbType.VarChar).Value = txtFirstName.Text;
cmd.Parameters.AddWithValue("@LastName", SqlDbType.VarChar).Value = txtLastName.Text;
cmd.Parameters.AddWithValue("@Email", SqlDbType.VarChar).Value = txtEmail.Text;
cmd.Parameters.AddWithValue("@Contact", SqlDbType.VarChar).Value = txtContact.Text;
cmd.Parameters.AddWithValue("@House", SqlDbType.VarChar).Value = "";
cmd.Parameters.AddWithValue("@street", SqlDbType.VarChar).Value = "";
cmd.Parameters.AddWithValue("@colony", SqlDbType.VarChar).Value = "";
cmd.Parameters.AddWithValue("@city", SqlDbType.VarChar).Value = "";
cmd.Parameters.AddWithValue("@state", SqlDbType.VarChar).Value = "";
cmd.Parameters.AddWithValue("@country", SqlDbType.VarChar).Value = txtCountry.Text;
cmd.Parameters.AddWithValue("@Added_on", SqlDbType.VarChar).Value = DateTime.Now.ToString("MMM dd yyyy");
EcomConString.Open();
exec=Convert.ToInt32(cmd.ExecuteScalar());
EcomConString.Close();

Answers (2)