There seems to be a problem with the following code I would like to insert a value in the database using the following code snippet.
DataTable dtUsers = new DataTable("tblUsers");
BindingSource bsUsers = new BindingSource();
SqlDataAdapter daUsers = new SqlDataAdapter("usp_GetUsers", Properties.Resources.ConnectionString);
daUsers.InsertCommand = new SqlCommand("usp_InsertNewUser");
daUsers.InsertCommand.Connection = new SqlConnection(Properties.Resources.ConnectionString);
daUsers.InsertCommand.CommandType = CommandType.StoredProcedure;
daUsers.InsertCommand.Parameters.Clear();
daUsers.InsertCommand.Parameters.Add("@username", SqlDbType.VarChar, 50).Value = txtUser.Text;
daUsers.InsertCommand.Parameters.Add("@password", SqlDbType.VarChar, 50).Value = txtPass.Text;
daUsers.InsertCommand.Parameters.Add("@userType", SqlDbType.Int).Value = cbxUserType.SelectedValue;
daUsers.Update(dtUsers);
And before you ask, the stored procedure is working fine. And also if I change the InsertCommand above to SelectCommand and call the Fill method, then everything works fine! This thing is frustrating as the Insert/update methods of the data adapter is not working as it should if you are using Select/Fill combo. No data rows are being inserted as I monitored that as well. Also no exceptions are generated. Al