Hi,
I am trying to learn ADO.net and I keep running into
problems trying to insert data into my Access Database:
data.mdb.
here is my code:
<code>
// Database Variables
private string connectionStr = @"Jet
OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry
Path=;Jet OLEDB:Database Locking Mode=1;Data
Source=""C:\data.mdb"";Jet OLEDB:Engine
Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet
OLEDB:System database=;Jet OLEDB:SFP=False;persist
security info=False;Extended Properties=;Mode=Share Deny
None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create
System Database=False;Jet OLEDB:Don't Copy Locale on
Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;User ID=Admin;Jet OLEDB:Global Bulk
Transactions=1";
private string selectStr = "Select id,
date, day, time, comments, timeout, status, process from
data";
private System.Data.DataSet myDataSet;
private System.Data.OleDb.OleDbConnection
myConnection;
private
System.Data.OleDb.OleDbDataAdapter myDataAdapter;
private
System.Data.OleDb.OleDbCommandBuilder myCmdBuilder;
private System.Data.OleDb.OleDbCommand
mySelectCmd;
public Schedule()
{
this.InitilizeDb();
this.PopulateDataSet();
}
private OleDbConnection ConnectDb()
{
return new OleDbConnection
(connectionStr);
}
public void InitilizeDb()
{
myDataAdapter = new
OleDbDataAdapter();
myCmdBuilder = new
OleDbCommandBuilder(myDataAdapter);
myDataSet = new DataSet();
}
private void PopulateDataSet()
{
// get the connection object
myConnection = (OleDbConnection)
this.ConnectDb();
// Initilize the Select Command
mySelectCmd = new OleDbCommand
(selectStr, myConnection);
// Define that the Select Command
is an SQL statement
mySelectCmd.CommandType =
CommandType.Text;
try
{
myConnection.Open();
myDataAdapter.SelectCommand = mySelectCmd;
// Populate the DataSet
from the "data" table
myDataAdapter.Fill
(myDataSet,"data");
}
finally
{
myConnection.Close();
}
}
public string InsertSchedule(string date,
string day, string time, string process,
string comments, string timeout,
string status)
{
// get the connection object
myConnection = (OleDbConnection)
this.ConnectDb();
try
{
myConnection.Open();
// create a new row to
insert the data into
DataRow newRow =
myDataSet.Tables["data"].NewRow();
// initilize the new row
newRow["id"] = 3;
newRow["date"] = date;
newRow["day"] = day;
newRow["time"] = time;
newRow["process"] =
process;
newRow["comments"] =
comments;
newRow["timeout"] =
timeout;
newRow["status"] = status;
// add the new row into
the dataset
myDataSet.Tables
["data"].Rows.Add(newRow);
myDataAdapter.Update
(myDataSet, "data");
return "true";
}
catch(Exception e)
{
return e.Message + "\n\n"
+ e.StackTrace + "\n\n" + e.InnerException;
}
finally
{
myConnection.Close();
}
}
</code>
the problem is when I try to insert into the database, I
keep getting this Exception Message:
<code>Syntax error in INSERT INTO statement.
at System.Data.Common.DbDataAdapter.Update(DataRow[]
dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet
dataSet, String srcTable)
at ShutdownMgr.Schedule.InsertSchedule(String date,
String day, String time, String process, String comments,
String timeout, String status) in c:\documents and
settings\azel\my documents\visual studio
projects\shutdownmgr\schedule.cs:line 99
</code>
I have tried different ways but none were successful. Is
anyone able to spot where I am going wrong? X|
thanks. 1 4089
Yeah, I never actually see a Insert statement either.
"Azel" <me@azellow.com> wrote in message
news:05****************************@phx.gbl...
Hi,
I am trying to learn ADO.net and I keep running into
problems trying to insert data into my Access Database:
data.mdb.
here is my code:
<code>
// Database Variables
private string connectionStr = @"Jet
OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry
Path=;Jet OLEDB:Database Locking Mode=1;Data
Source=""C:\data.mdb"";Jet OLEDB:Engine
Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet
OLEDB:System database=;Jet OLEDB:SFP=False;persist
security info=False;Extended Properties=;Mode=Share Deny
None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create
System Database=False;Jet OLEDB:Don't Copy Locale on
Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;User ID=Admin;Jet OLEDB:Global Bulk
Transactions=1";
private string selectStr = "Select id,
date, day, time, comments, timeout, status, process from
data";
private System.Data.DataSet myDataSet;
private System.Data.OleDb.OleDbConnection
myConnection;
private
System.Data.OleDb.OleDbDataAdapter myDataAdapter;
private
System.Data.OleDb.OleDbCommandBuilder myCmdBuilder;
private System.Data.OleDb.OleDbCommand
mySelectCmd;
public Schedule()
{
this.InitilizeDb();
this.PopulateDataSet();
}
private OleDbConnection ConnectDb()
{
return new OleDbConnection
(connectionStr);
}
public void InitilizeDb()
{
myDataAdapter = new
OleDbDataAdapter();
myCmdBuilder = new
OleDbCommandBuilder(myDataAdapter);
myDataSet = new DataSet();
}
private void PopulateDataSet()
{
// get the connection object
myConnection = (OleDbConnection)
this.ConnectDb();
// Initilize the Select Command
mySelectCmd = new OleDbCommand
(selectStr, myConnection);
// Define that the Select Command
is an SQL statement
mySelectCmd.CommandType =
CommandType.Text;
try
{
myConnection.Open();
myDataAdapter.SelectCommand = mySelectCmd;
// Populate the DataSet
from the "data" table
myDataAdapter.Fill
(myDataSet,"data");
}
finally
{
myConnection.Close();
}
}
public string InsertSchedule(string date,
string day, string time, string process,
string comments, string timeout,
string status)
{
// get the connection object
myConnection = (OleDbConnection)
this.ConnectDb();
try
{
myConnection.Open();
// create a new row to
insert the data into
DataRow newRow =
myDataSet.Tables["data"].NewRow();
// initilize the new row
newRow["id"] = 3;
newRow["date"] = date;
newRow["day"] = day;
newRow["time"] = time;
newRow["process"] =
process;
newRow["comments"] =
comments;
newRow["timeout"] =
timeout;
newRow["status"] = status;
// add the new row into
the dataset
myDataSet.Tables
["data"].Rows.Add(newRow);
myDataAdapter.Update
(myDataSet, "data");
return "true";
}
catch(Exception e)
{
return e.Message + "\n\n"
+ e.StackTrace + "\n\n" + e.InnerException;
}
finally
{
myConnection.Close();
}
}
</code>
the problem is when I try to insert into the database, I
keep getting this Exception Message:
<code>Syntax error in INSERT INTO statement.
at System.Data.Common.DbDataAdapter.Update(DataRow[]
dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet
dataSet, String srcTable)
at ShutdownMgr.Schedule.InsertSchedule(String date,
String day, String time, String process, String comments,
String timeout, String status) in c:\documents and
settings\azel\my documents\visual studio
projects\shutdownmgr\schedule.cs:line 99
</code>
I have tried different ways but none were successful. Is
anyone able to spot where I am going wrong? X|
thanks. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jared Evans |
last post by:
I developed a console application that will continually check a message
queue to watch for any incoming data that needs to be inserted into MS
SQL database.
What would be a low-cost method I...
|
by: James Alba |
last post by:
Hey all,
I am accessing an ms access database using .NET and C#. Like so,
/* Create the database connection. */
connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data...
|
by: c676228 |
last post by:
Hi everyone,
I am just wodering in asp program, if there is anybody writing store
procedure for inserting data into database since there are so many parameters
need to be passed into store...
|
by: yzlin04 |
last post by:
Hello,
I'm new in vb.net. I have a problem in inserting a new row to a MS Access database table.
There is no error message comes out when i run my program, but when i check my MS Access table,...
|
by: Surya |
last post by:
Dear All,
I have problem on inserting a record to database..Although it looked
easy.. i have caught up with following issue .. please go ahead and
help me to find solution
I Need to insert...
|
by: SL Culby |
last post by:
Hello everyone, I have a project where I pull SQL Server data put it into a dataset and now I have to put the dataset data into an Access Database. The dataset currently is over 2000 row, so looping...
|
by: hotflash |
last post by:
Hi Mark et All,
I understand that you created a very professional document and a similar issue forum out there regarding to Inserting the checkbox value into MS Access using ASP however; I am so...
|
by: ashes |
last post by:
Hi,
I am creating an ecommerce website using Microsoft Visual Studio, VB.Net and MS Access 2003. I am new to VB.Net
When someone wants to register on the website, they fill out a form and the...
|
by: Bunty |
last post by:
I am not beginer of this language. I've worked on this language for 2
or 3 months.But now i have a problem to inserting values in the
database.It gives me error that DATABASE NOT SELECTED.
I am...
|
by: hakkatil |
last post by:
Hi to all,
I have a page that inserts excel sheet to access database. I am using asp. What I want to do is to check the inserting record if it is in the database. Basicly checking the dublicate...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |