[英]Cannot insert the value NULL into column 'UID'
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.希望大家都没事,我需要你的帮助,因为我正在尝试将值插入到 MS SQL 表中,但我面临一个问题,因为我有一个主列,它是 AdsID,它的值类型是 Int,它的标识增量。
PLEASE: when you answer can you explain in Simply and detailed as i am not professional one in c#.请:当你回答时,你能简单详细地解释一下,因为我不是 C# 专业人士。
the error message is: Line: 940 Error: Sys.WebForms.PageRequestManagerServerErrorException: Cannot insert the value NULL into column 'UID', table 'Berava.dbo.ads';错误消息是:行:940 错误:Sys.WebForms.PageRequestManagerServerErrorException:无法将值 NULL 插入列 'UID'、表 '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");
}
So what is the problem?那么问题是什么? If you bother reading it tells you that clear - not understanding this means "read books about sql".
如果你费心阅读它会告诉你很清楚 - 不理解这意味着“阅读关于 sql 的书籍”。 The table has a field that is not allowed t obe NULL and your insert does not insert data, so it would be a NULL.
该表有一个不允许为 NULL 的字段,并且您的插入不会插入数据,因此它将是一个 NULL。 The column is - as it states clearly in the error "UID"
该列是 - 正如它在错误“UID”中明确说明的那样
How do you fis that?你是怎么解决的? Well... can we start some basic logic.
嗯...我们可以开始一些基本的逻辑。 Table has field that has to ahve a value, error is you do not provide value.
表具有必须有值的字段,错误是您没有提供值。 SImple logic: Provide value, so the data can be inserted.
简单的逻辑:提供值,所以数据可以插入。
Simple enough terms?足够简单的术语?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.