Hope everyone are ok, i need your help as i am trying to insert value into a MS SQL table but i am facing a problem as i have a primary column which is AdsID and its value type is Int and its identity increment.
PLEASE: when you answer can you explain in Simply and detailed as i am not professional one in c#.
the error message is: Line: 940 Error: Sys.WebForms.PageRequestManagerServerErrorException: Cannot insert the value NULL into column 'UID', table 'Berava.dbo.ads'; column does not allow nulls. INSERT fails. The statement has been terminated.
and behind code is:
protected void addadsbtn_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(sc);
SqlCommand cmd = new SqlCommand();
string sqlstatment = "INSERT INTO ads ( CateAct, State, City, AdsTit, AdsDesc, AdsPrice, Img1, img2, img3, img4, img5, Wtags) VALUES ( @CateAct, @State, @City, @AdsTit, @AdsDesc, @AdsPrice, @Img1, @img2, @img3, @img4, @img5, @Wtags)";
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlstatment;
//Insert the parameters first
cmd.Parameters.AddWithValue("@CateAct", Catedrdoads.Text);
cmd.Parameters.AddWithValue("@State", lanadsadddrdo.Text);
cmd.Parameters.AddWithValue("@City", adsaddcitytxtbx.Text);
cmd.Parameters.AddWithValue("@AdsTit", addadstittxtbx.Text);
cmd.Parameters.AddWithValue("@AdsDesc", Adsadddestxtbox.Text);
cmd.Parameters.AddWithValue("@AdsPrice", adsaddpristxtbx.Text);
cmd.Parameters.AddWithValue("@Img1", FileUploadImg1.FileName);
cmd.Parameters.AddWithValue("@Img2", FileUploadImg2.FileName);
cmd.Parameters.AddWithValue("@Img3", FileUploadImg3.FileName);
cmd.Parameters.AddWithValue("@Img4", FileUploadImg4.FileName);
cmd.Parameters.AddWithValue("@Img5", FileUploadImg5.FileName);
cmd.Parameters.AddWithValue("@Wtags", addadswtagtxtbtn.Text);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ad.SelectCommand = cmd;
ad.Fill(ds);
Response.Redirect("User panel.aspx");
}