|
-
May 30th, 2007, 06:10 AM
#1
Thread Starter
Addicted Member
[2.0] Date Format
I don't really understand why this code doesn't work?
Code:
dr.BeginEdit();
dr["ACSDate"] = hdnField.Value;
dr["FormNum"] = txtFormNumberNew.Text;
dr["ResponsiblePerson"] = txtResponsiblePersonNew.Text;
dr["SiteCodeID"] = GlobalVariable.g_sitecodeID;
dr.EndEdit();
da.Update(ds, "tblAsset");
ds.AcceptChanges();
The error says,
Incorrect date value: '5/30/2007 7:07:13 PM' for column 'ACSDate' at row 1
The value of hdnField.Value was taken in this code:
Code:
DateTime timeNow = DateTime.Now;
string myTime = timeNow.ToString("h:mm:ss tt");
string acsdate = ddlMonth.SelectedValue + "/" + ddlDays.SelectedValue + "/" + ddlYear.SelectedValue + " " + myTime;
hdnField.Value = acsdate;
What I am using is ASP.net using C# and my database is MySQL AB Database.
Last edited by jsc0624; May 30th, 2007 at 06:48 AM.
-
May 30th, 2007, 07:40 AM
#2
Re: [2.0] Date Format
Strings are not dates. If your column is supposed to contains dates then assign a DateTime object to it, not a string.
-
May 30th, 2007, 07:46 AM
#3
Thread Starter
Addicted Member
Re: [2.0] Date Format
Code:
DateTime myTime = timeNow.ToString("h:mm:ss tt");
DateTime acsdate = ddlMonth.SelectedValue + "/" + ddlDays.SelectedValue + "/" + ddlYear.SelectedValue + " " + myTime;
hdnField.Value = acsdate;
I tried to change it to DateTime but the the error message says:
Cannot implicitly convert type 'string' to 'System.DateTime'
Cannot implicitly convert type 'string' to 'System.DateTime'
Cannot implicitly convert type 'System.DateTime' to 'string'
That's why I tried to use String!
I need your help!
-
May 30th, 2007, 07:51 AM
#4
Re: [2.0] Date Format
If you have a date/time column in a database then you should be using DateTime objects in your VB code, NOT Strings. Do NOT create a string. Create a DateTime object. This code:
Code:
ddlMonth.SelectedValue + "/" + ddlDays.SelectedValue + "/" + ddlYear.SelectedValue + " " + myTime;
is creating a string. If you want to create a DateTime object then you use a constructor of the DateTime type.
-
May 30th, 2007, 07:55 AM
#5
Thread Starter
Addicted Member
Re: [2.0] Date Format
How can I convert it to DateTime?
I tried to removed this "/";
But then the error says that the ddlMonth contains a string, it cannot be implicitly converted to System.DateTime.
-
May 30th, 2007, 08:00 AM
#6
Re: [2.0] Date Format
I've told you that you need to use a DateTime constructor to create a DateTime object. Have you looked to see what constructors the DateTime structure has? I'm guessing not. I suggest you do so. Once you have then you'll know what values you need to provide to create a DateTime object. You then need to ask yourself what values you have and how you would go about converting from one to the other.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|