Click to See Complete Forum and Search --> : ADO.Net and Access Database


XxXxX
June 20th, 2003, 04:21 PM
I have difficulty to insert a record into an Access Database. The code I used is like:

OleDbCommand comm = new OleDbCommand();
comm.Connection = new OleDbConnection(Constants.AccessConnectionString);
comm.Connection.Open();

foreach(DataRow dr in ds.Tables[0].Rows)
{
comm.CommandText = BuildInsertSQL(dr);
comm.ExecuteNonQuery();
}
comm.Connection.Close();
comm = null;

When it executes, the ExecuteNonQuery() will throw exception. Message reads "Syntax Error in INSERT INTO statement"

For the connection string, it is correct as I can execute SELECT queries in other classes I wrote. For the sql returned from BuildInserSQL, it is right since I copied in and pasted in the Access as a query and it executes without problem.

The insert statement is like:
Insert into GeoData(DataProvider, StateName, CountyName, Format, Resolution, Projection, Type, Quad, Half, MinX, MaxX, MinY, MaxY, URL, Zone) values('webgis','Alaska','ALEUTIANS EAST BOROUGH','DEM','1','Lat/Long','','CHIGNIK','E',-1590000,-1580000, 560000, 570000,'http://Server.com/file.zip','');

Any suggestion as what might be the problem?

hellomadhu
June 23rd, 2003, 01:09 AM
try running your insert statement from acces.
you will be able to identify exactly if there is any error in the insert statement.

XxXxX
June 23rd, 2003, 10:04 PM
I tested it (the insert statement) in Access and there's no error. I'm wondering what the problem might be.

riscoh
August 4th, 2003, 08:51 AM
are using parameters..................


if yes...................... you have to use just ? ..................... unlike sqlclient where you use @name.............