|
-
September 15th, 2005, 01:06 AM
#1
OleDb Date Time insertion Problem
Hi,
I'm having problems inserting datetime into and access database as shown below
string insert = "insert into " + TableName + " (Name,Location,Date) ";
insert += " values('" + row["Name"] + "','" + row["Location"];
insert += "','#2/2/2004#')";
System.Data.OleDb.OleDbCommand cmd = new
System.Data.OleDb.OleDbCommand(insert,this.Connection);
cmd.ExecuteNonQuery();
or even with this
System.Data.OleDb.OleDbCommand cmd = database.CreateCommand();
cmd.CommandText = "insert into "+ TableName +" (Name,Location,Date)"+" values(?,?,?)";
cmd.Parameters.Add("Name",System.Data.OleDb.OleDbType.VarChar,40,"Name");
cmd.Parameters.Add("Location",System.Data.OleDb.OleDbType.VarChar,40,"Location");
cmd.Parameters.Add("Date",System.Data.OleDb.OleDbType.Date,0,"Date");
in both cases I get "syntax error in insert into statement"
The Date field is defined as "General Date", but I get the same thing with "Short Date"
If I take the parts to do with the date it works
Help Please
Last edited by RMirenzi; September 15th, 2005 at 01:17 AM.
Reason: change title
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
|