473,395 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Adding new rows to empty table

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);
Nov 16 '05 #1
3 2309
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 Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"news.microsoft.com" <cb******@yahoo.com.au> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
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);


Nov 16 '05 #2
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 Lapshin [C# / .NET MVP] wrote:
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.

Nov 16 '05 #3
Dmitriy,

Thanks for your help.

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

Doh!!

Cheers,
Craig
Dmitriy Lapshin [C# / .NET MVP] wrote:
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.

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Bobbak | last post by:
Hello All, I have these tables (lets call it ‘EmpCalls', ‘EmpOrders', and ‘Stats') that each contain the list of EmployeeIDs, I want to be able to create a Module in which I could call in my VB...
0
by: news.microsoft.com | last post by:
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...
0
by: Fabrizio | last post by:
Hi, I need to dynamically add rows and cells with controls like textbox to an empty table. After adding controls to cells, i add cell to rows and at the end add the rows to the table, but the...
3
by: Arek | last post by:
I need to have a simple table. User and application will add rows to it. I've used DataGrid but I can't add rows by application. I've got such code: DataRow row = dataTable.NewRow();...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
0
by: Luis Esteban Valencia | last post by:
Hello I wrote a program with code behind in C# to add row into table dynamically and the program worked very well in .Net Framework 1.1. When I run this program in .Net Framework 2.0 beta...
2
by: Niels Jensen | last post by:
I have the following code in a Sub which is called by a do loop statement for each line starting with unit info in an e-mail based game that I play. I'm exctracting the keywords from the text and...
3
by: didi86 | last post by:
Please help me to adding multiple row at a time... // Last updated 2006-02-21 <script language="javascript"> function addRowToTable() { var tbl = document.getElementById('tblSample'); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.