列不允许空值 [英] Column does not allow nulls
问题描述
请看看我下面的code,告诉我在哪里,我错了。
Please have a look at my code below and tell me where i am going wrong.
case "particulars.aspx":
dt = JobCardManager.GetParticularsByJobId(id);
hidJobId.Value = id.ToString();
if (dt != null && dt.Rows.Count > 0)
{
gvParticulars.DataSource = dt;
gvParticulars.DataBind();
}
else
{
**dt.Rows.Add(dt.NewRow());**
gvParticulars.DataSource = dt;
gvParticulars.DataBind();
int TotalColumns = gvParticulars.Rows[0].Cells.Count;
gvParticulars.Rows[0].Cells.Clear();
gvParticulars.Rows[0].Cells.Add(new TableCell());
gvParticulars.Rows[0].Cells[0].ColumnSpan = TotalColumns;
gvParticulars.Rows[0].Cells[0].Text = "No Record Found";
}
ddlJobs.Enabled = false;
gvParticulars.ShowFooter = true;
break;
我想实现的是,在情况下,当 DT
没有任何行,我需要显示在页脚中的新行,管制已添加在页脚。我的INSERT,UPDATE和添加新过程中的所有从电网本身进行。
What I want to achieve is that in case when the dt
don't have any rows, I need to display a new row in the footer, controls are already added in footer. My insert update and add new process all are carried out from grid itself.
所以,如果,如果我的数据表来空,然后在星号线,我得到的错误,列不允许空。凡在数据库中的所有列都允许空复选框被选中。请大家帮帮忙。
So in case if my datatable comes null, then at the starred line, I am getting the error, "Column does not allow null". Where in database all columns have Allow Null checkboxes are checked. Please help.
[更新]
我不retriving在查询中的主键。只有表的编辑区域。
I am not retriving primary key in the query. Only the editable parts of the table.
推荐答案
您可能想读取架构信息,当您填写的数据集。我不知道这是否会解决您的问题,但我怀疑它会的。如果没有模式,您的数据表将不知道该列是否接受空或不是。</ P>
You might want to read the schema information when you fill the dataset. I'm not sure whether this would solve your problem, but I suspect it will. Without the schema, your datatable won't know whether the column accepts null or not.
da.FillSchema(ds, SchemaType.Source);
da.Fill(ds);
这篇关于列不允许空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!