tmcmaster
asked on
C# Insert statement
I'm having a terrible time attempting to get an INSERT statement to work in ASP.NET usinc C#. I have look everywhere for the answer to no avail.
Ted
Ted
ASKER
I should have given more information.
I am using the OleDB connections and trying to talk Insert into a Foxpro database
.
I am using the OleDB connections and trying to talk Insert into a Foxpro database
.
the principle is the same.
use OleDbConnection instead of SqlConnection, and OleDbCommand instead of SqlCommand etc.
use OleDbConnection instead of SqlConnection, and OleDbCommand instead of SqlCommand etc.
ASKER
I have done that, but I still get different types of errors . What I would like if possible the syntax for the INSERT string. If they are identical then I can reseach SQL syntax.
Thanks,
Ted
Thanks,
Ted
the INSERT syntax purely depends on the database you are using.
if you posted what you tried with the error you got, it would be easier to help with concrete corrections.
if you posted what you tried with the error you got, it would be easier to help with concrete corrections.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the best method to avoid data type translations problems is to use bound parameters.
check out OleDbParameter for your OleDbCommand:
http://www.java2s.com/Tutorial/CSharp/0560__ADO.Net/OleDbParameterExample.htm
the relevant part is here:
check out OleDbParameter for your OleDbCommand:
http://www.java2s.com/Tutorial/CSharp/0560__ADO.Net/OleDbParameterExample.htm
the relevant part is here:
// specify the sql statement with a place holder for the parameter (?):
string selstr = "select firstName from Employee where lastname = ?";
// fill in the parameter specification: name, type, size:
OleDbParameter name = cmd.Parameters.Add( "@name", OleDbType.VarChar, 15 );
// and the value
name.Value = "Tang";
note: as you can see, the code has no quotes for the string value. OleDbCommand + OleDbParameter will bind the value. no need for the quote. the same will be true for date values.
ASKER
How does this relate to the INSERT function?
ASKER
the situation now.
have a string date 7/18/2009 and need to convert it to a foxpro date field.
have a string time 12:00 PM and need to convert it to a time field.
In other words I need to figure out how to do these conversions the simplest way.
Thanks
have a string date 7/18/2009 and need to convert it to a foxpro date field.
have a string time 12:00 PM and need to convert it to a time field.
In other words I need to figure out how to do these conversions the simplest way.
Thanks
SELECT or INSERT does not matter, in regards to the parameter handling...
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson03.aspx
apart from that: without getting more precise status of what you have and what you get...