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?
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?