This code is not working. I'm trying to insert the data into SQL Server:
int a = 1;
DateTime cDate;
cDate = DateTime.Today;
string insertString = "insert into tbl_complaint(Date, User_id, department_name, Product_name, complaint_details, Status) values (@date, @uid, @dept, @product, @details, @status)";
SqlCommand cmd = new SqlCommand(insertString, con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@date", cDate);
cmd.Parameters.AddWithValue("@uid", a);
cmd.Parameters.AddWithValue("@dept", ddlDept.SelectedValue);
cmd.Parameters.AddWithValue("@product", txtPName.Text);
cmd.Parameters.AddWithValue("@details", txtCDes.Text);
cmd.Parameters.AddWithValue("@status", "Submited");
try {
int check;
con.Open();
check= cmd.ExecuteNonQuery();
con.Close();
}
The error that I get:
SqlException (0x80131904):
Cannot insert the value NULL into column 'Complaint_id', table 'complaint_management.dbo.tbl_complaint'; column does not allow nulls.
INSERT fails. The statement has been terminatedSystem.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +2442126
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +5736904