Q: exception on DateTime field

G

Guest

Hello,
I am using the following code to update my table through datagrid, it works
fine if I have all the field as nvarchar, if I have DateTime type filed it
raises exception by saying “String was not recognized as a valid DateTimeâ€,
how can I solve it?

protected void DataGrid1_Update(Object sender, DataGridCommandEventArgs e)
{
string debug="No Errors On Update.";
int numCols = e.Item.Cells.Count;

int key = (int)DataGrid1.DataKeys[e.Item.ItemIndex];
DataRow dr= dataSet11.tPatient.FindByPatientID(key);
NUM_LINK_COLUMNS=3;
try
{
for (int i=NUM_LINK_COLUMNS+1; i<numCols; i++)
{
string colvalue =((TextBox)e.Item.Cells.Controls[0]).Text;
dr[i-NUM_LINK_COLUMNS]= colvalue;
}
sqlDataAdapter1.Update(dataSet11);
DataGrid1.EditItemIndex = -1;
}
catch (Exception exc)
{
debug= exc.Message;
}
ResetPageIndex(DataGrid1,view);
DataGrid1.DataBind();
textBoxMessage.Text= debug;
}
Thanks,
Jim.
 
G

Guest

I found the reason. It seems it requires date to be entered with date format,
can not be left blank. Can I set my date fields in datagrid to a default
value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top