Adding new rows to empty table

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

Hi,

I am having trouble adding new rows to an empty MS Access table.
I manually created the table in MS access named server and created two
columns Date & Time.
When I run the following code I get: "Syntax error in INSERT INTO
statement".

Any help would be great.
Thank you.

OleDbCommand fgSelectCommand = conn.CreateCommand();

fgSelectCommand.CommandText = "SELECT TOP 1 * FROM Server";

OleDbDataAdapter fgADOAdapter = new OleDbDataAdapter();

OleDbCommandBuilder fgCommandBuilder = new
OleDbCommandBuilder(fgADOAdapter);

fgADOAdapter.SelectCommand = fgSelectCommand;

DataTable fgDataTable = new DataTable("Server");

fgADOAdapter.FillSchema(fgDataTable, SchemaType.Source);


DataRow fgDataRow = fgDataTable.NewRow();


fgDataRow["Date"] = logWeb.LogDate;

fgDataRow["Time"] = logWeb.LogTime;


fgDataTable.Rows.Add(fgDataRow);


fgADOAdapter.Update(fgDataTable);
 
Hi,

You might want to look at the generated INSERT statement and figure out what
is wrong with its syntax.
Moreover, the automatic update scenario you use requires a primary key to be
present in the data table. Ensure this condition is also satisfied.
 
Dmitriy,

The Insert statement as follows:
INSET INTO Server(Date, Time)VALUES(?, ?)

It seems that OleDbCommandBuilder is not getting the values for the
columns.
How is it meant to get the values for the Auto Genereated SQL Command??
Is there a way for me to see what commandBuilder is looking at??

Cheers.
 
Dmitriy,

Thanks for your help.

I realised that I was using Date & Time as my column names!

Doh!!

Cheers,
Craig
 
Back
Top