473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Q: exception on DateTime field

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[i].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.

Nov 19 '05 #1
1 1032
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.
"JIM.H." wrote:
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[i].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.

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: cody | last post by:
public DateTime Value { get { try { return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text), int.Parse(tbDay.Text)); } catch (FormatException)
6
by: Carl | last post by:
Hi, to be use with SQL server database 1- From window form textbox object From this assignement, txtTOTAL.Text="0.00m"; How do you convert back to decimal type ? How do you assign a...
8
by: Robert Gravereaux | last post by:
I've noticed that the first exception thrown/caught by an app running in debug is very slow - it takes perhaps 7 or 8 seconds on my P4 machine. I've noticed this on several different machines...
6
by: FatboyCanteen | last post by:
When I using dataset to append a null value to the datetime field. It throw a error -> can not convert db.null to system.date Can there is any standard to pass a Null value to the DateTime...
0
by: Glenn Venzke | last post by:
I have an aspx page that is set up to copy backed-up DB files from a shared directory to a local folder. For some reason, it is being denied access to the network share. I have the web app running...
0
by: stand__sure | last post by:
in re-reading something on .NET remoting I realized that I had done nothing with lease sponsorship and renewal. so, I dug around in msdn2 and found this topic...
5
by: Rob Dob | last post by:
I am trying to set the NullValue within the Column properties of my Dataset in VS2005. The DataType is a System.DateTime. and when I try and change it from "(Throw Exception)" I get the following...
5
by: iulian.ilea | last post by:
Is correct to have a varchar field and insert dates of type dd/mm/yyyy into it? I choose this method because I have an application that runs on more than one server. So, if I used a datetime field...
4
by: Bill Gower | last post by:
Why won't this work? What do I need to do to make it work? DateTime? DateMember; if((DateTime.Parse(oldRow.ToString) == null)) DateMember = null; else DateMember =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.