I'm trying to insert data to data base, first i used tray catch and debugging. there was no error but data didn't insert. then i remove try catch and find this:
"Cannot insert the value NULL into column 'ContactID', table 'Contact_DB3.dbo.TContacts'; column does not allow nulls."
My inputs isn't null how can i fix this?
public bool Insert(string name, string family, string mobile)
{
SqlConnection connection = new SqlConnection(connectionstring);
string query = "insert into TContacts (Name,Family,Mobile) Values ( @Name , @Family , @Mobile ) ";
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.AddWithValue("@Name", name);
command.Parameters.AddWithValue("@Family", family);
command.Parameters.AddWithValue("@Mobile", mobile);
connection.Open();
command.ExecuteNonQuery();
return true;
connection.Close();
}
If your table does not allow null as per your question the column is ContactID. You cna do one of 2 things.