Reputation:
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;
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.
[Update]
I am not retriving primary key in the query. Only the editable parts of the table.
Upvotes: 1
Views: 4557
Reputation: 6891
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);
Upvotes: 2