473,399 Members | 3,832 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,399 software developers and data experts.

insert a data record into a data table of a access database(mdb)

I use the following code to insert a data record in to a datatable of an
access database.But every time I execute the command, there will rise an
exception and the insert operation can't be completed.
here's the code:
System.Data.OleDb.OleDbConnection hist_cnn = new
System.Data.OleDb.OleDbConnection();

System.Data.OleDb.OleDbCommand hist_command = new
System.Data.OleDb.OleDbCommand();

System.Data.DataSet hist_data = new System.Data.DataSet();

hist_command.CommandText="insert into hist_data_record
(record_id) values('2003') ";

hist_cnn.ConnectionString="Provider=Microsoft.Jet. OLEDB.4.0;"
+ "Data Source=history_data.mdb;" + "Jet OLEDB:Engine Type=5";

hist_cnn.Open();

hist_command.Connection=hist_cnn;

hist_command.ExecuteNonQuery();//rise a exception and the
operation ended

I want to know where the problems is.

Nov 16 '05 #1
4 11804
authorking,

Does it give any more information than that in the exception? There
should be more information than that in the exception message and the call
stack (for example, it was a COM error code that was returned, what is
that?).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"authorking" <au************@hotmail.com> wrote in message
news:e9*************@TK2MSFTNGP09.phx.gbl...
I use the following code to insert a data record in to a datatable of an
access database.But every time I execute the command, there will rise an
exception and the insert operation can't be completed.
here's the code:
System.Data.OleDb.OleDbConnection hist_cnn = new
System.Data.OleDb.OleDbConnection();

System.Data.OleDb.OleDbCommand hist_command = new
System.Data.OleDb.OleDbCommand();

System.Data.DataSet hist_data = new System.Data.DataSet();

hist_command.CommandText="insert into hist_data_record
(record_id) values('2003') ";

hist_cnn.ConnectionString="Provider=Microsoft.Jet. OLEDB.4.0;" + "Data Source=history_data.mdb;" + "Jet OLEDB:Engine Type=5";

hist_cnn.Open();

hist_command.Connection=hist_cnn;

hist_command.ExecuteNonQuery();//rise a exception and the
operation ended

I want to know where the problems is.


Nov 16 '05 #2
The more information given by system is :
"Unhandled"System.Data.OleDb.OleException" exception rised in
system.data.dll"

Is there any better menthod to insert a data record into an access database
table?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> дÈëÓʼþ
news:e8**************@tk2msftngp13.phx.gbl...
authorking,

Does it give any more information than that in the exception? There
should be more information than that in the exception message and the call
stack (for example, it was a COM error code that was returned, what is
that?).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"authorking" <au************@hotmail.com> wrote in message
news:e9*************@TK2MSFTNGP09.phx.gbl...
I use the following code to insert a data record in to a datatable of an
access database.But every time I execute the command, there will rise an
exception and the insert operation can't be completed.
here's the code:
System.Data.OleDb.OleDbConnection hist_cnn = new
System.Data.OleDb.OleDbConnection();

System.Data.OleDb.OleDbCommand hist_command = new
System.Data.OleDb.OleDbCommand();

System.Data.DataSet hist_data = new System.Data.DataSet();

hist_command.CommandText="insert into hist_data_record
(record_id) values('2003') ";

hist_cnn.ConnectionString="Provider=Microsoft.Jet. OLEDB.4.0;"
+ "Data Source=history_data.mdb;" + "Jet OLEDB:Engine Type=5";

hist_cnn.Open();

hist_command.Connection=hist_cnn;

hist_command.ExecuteNonQuery();//rise a exception and the
operation ended

I want to know where the problems is.



Nov 16 '05 #3
authorking,

That's probably the way you do it. Can you give a short example, as
well as post the MDB that you are trying to insert the record into that
displays the problem?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"authorking" <au************@hotmail.com> wrote in message
news:um*************@TK2MSFTNGP09.phx.gbl...
The more information given by system is :
"Unhandled"System.Data.OleDb.OleException" exception rised in
system.data.dll"

Is there any better menthod to insert a data record into an access database table?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> дÈëÓʼþ news:e8**************@tk2msftngp13.phx.gbl...
authorking,

Does it give any more information than that in the exception? There
should be more information than that in the exception message and the call stack (for example, it was a COM error code that was returned, what is
that?).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"authorking" <au************@hotmail.com> wrote in message
news:e9*************@TK2MSFTNGP09.phx.gbl...
I use the following code to insert a data record in to a datatable of an access database.But every time I execute the command, there will rise an exception and the insert operation can't be completed.
here's the code:
System.Data.OleDb.OleDbConnection hist_cnn = new
System.Data.OleDb.OleDbConnection();

System.Data.OleDb.OleDbCommand hist_command = new
System.Data.OleDb.OleDbCommand();

System.Data.DataSet hist_data = new System.Data.DataSet();
hist_command.CommandText="insert into hist_data_record
(record_id) values('2003') ";

hist_cnn.ConnectionString="Provider=Microsoft.Jet. OLEDB.4.0;"
+ "Data Source=history_data.mdb;" + "Jet OLEDB:Engine Type=5";

hist_cnn.Open();

hist_command.Connection=hist_cnn;

hist_command.ExecuteNonQuery();//rise a exception and the operation ended

I want to know where the problems is.




Nov 16 '05 #4
I create the databse with the follwing code. I really don't know why the
insert operation can't be completed.
databse creation code:
ADOX.CatalogClass cat = new ADOX.CatalogClass();//define a Jet database
class
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data
Source=history_data.mdb;" + "Jet OLEDB:Engine Type=5");//create a Jet
database
System.Data.OleDb.OleDbConnection hist_cnn = new
System.Data.OleDb.OleDbConnection();
System.Data.OleDb.OleDbCommand hist_command = new
System.Data.OleDb.OleDbCommand();
hist_command.CommandText="CREATE TABLE hist_data_record(record_id char(8)
NOT NULL PRIMARY KEY , ball_1 smallint NOT NULL , ball_2 smallint NOT NULL ,
ball_3 smallint NOT NULL , ball_4 smallint NOT NULL , ball_5 smallint NOT
NULL , ball_6 smallint NOT NULL)";
hist_cnn.ConnectionString="Provider=Microsoft.Jet. OLEDB.4.0;" + "Data
Source=history_data.mdb;" + "Jet OLEDB:Engine Type=5";
hist_cnn.Open();
hist_command.Connection=hist_cnn;
hist_command.ExecuteNonQuery();
hist_cnn.Close();

record inersting code:
System.Data.OleDb.OleDbConnection hist_cnn = new
System.Data.OleDb.OleDbConnection();
System.Data.OleDb.OleDbCommand hist_command = new
System.Data.OleDb.OleDbCommand();
System.Data.DataSet hist_data = new System.Data.DataSet();
hist_command.CommandText="insert into hist_data_record (record_id)
values('2003') ";
hist_cnn.ConnectionString="Provider=Microsoft.Jet. OLEDB.4.0;"
+ "Data Source=history_data.mdb;" + "Jet OLEDB:Engine Type=5";

hist_cnn.Open();

hist_command.Connection=hist_cnn;

hist_command.ExecuteNonQuery();//rise a exception and the
operation ended

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> дÈëÓʼþ
news:%2****************@TK2MSFTNGP11.phx.gbl...
authorking,

That's probably the way you do it. Can you give a short example, as
well as post the MDB that you are trying to insert the record into that
displays the problem?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"authorking" <au************@hotmail.com> wrote in message
news:um*************@TK2MSFTNGP09.phx.gbl...
The more information given by system is :
"Unhandled"System.Data.OleDb.OleException" exception rised in
system.data.dll"

Is there any better menthod to insert a data record into an access database
table?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>

дÈëÓʼþ
news:e8**************@tk2msftngp13.phx.gbl...
authorking,

Does it give any more information than that in the exception? There should be more information than that in the exception message and the call stack (for example, it was a COM error code that was returned, what is
that?).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"authorking" <au************@hotmail.com> wrote in message
news:e9*************@TK2MSFTNGP09.phx.gbl...
> I use the following code to insert a data record in to a datatable of an
> access database.But every time I execute the command, there will
rise
an > exception and the insert operation can't be completed.
> here's the code:
> System.Data.OleDb.OleDbConnection hist_cnn = new
> System.Data.OleDb.OleDbConnection();
>
> System.Data.OleDb.OleDbCommand hist_command = new
> System.Data.OleDb.OleDbCommand();
>
> System.Data.DataSet hist_data = new System.Data.DataSet(); >
> hist_command.CommandText="insert into
hist_data_record > (record_id) values('2003') ";
>
>
hist_cnn.ConnectionString="Provider=Microsoft.Jet. OLEDB.4.0;"
> + "Data Source=history_data.mdb;" + "Jet OLEDB:Engine Type=5";
>
> hist_cnn.Open();
>
> hist_command.Connection=hist_cnn;
>
> hist_command.ExecuteNonQuery();//rise a exception and

the > operation ended
>
> I want to know where the problems is.
>
>
>
>
>



Nov 16 '05 #5

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

Similar topics

6
by: DL | last post by:
Hi, Is it possible to use an access .mdb database file as a database? If so then how do I connect to it? (and make a sample query) I know you can add something in controlpanel>systemsettings >...
0
by: Schorschi | last post by:
I have an Access MDB that I have created via VB .NET, thus it is an emply database. I have an XML Schema file (.XSD) that has the schema for the database, how do I get the XML Schema into the...
3
by: Marcel | last post by:
Hi, I'm not shure if this is the right forum but the core program is VB.NET. So, my question is: can I create, open, read and write Access.mdb tables even if the user for which I'm writing a...
2
by: B.Newman | last post by:
I've got some VB.NET code that *should* get a list of reports from an Access MDB and populate a list box with them. It doesn't detect any of the reports at all. oAccess.Reports.Count comes up as...
3
by: genojoe | last post by:
I have tried everything I can think of to move records from one Access database to another. It should not be that hard. Read on.... I have identical access mdb's. One contains data; one...
2
by: Bill | last post by:
I have an Access 2003 database application that I split into an application component MDB file (i.e., forms, etc) and a data component MDB file (i.e., tables, etc.). I used the 2003 developer...
3
by: jc | last post by:
Hello. I want to ask about the possibility of copying both a table structure and it's contents from a SQL server table to a table within MS access. The problem cannot be solve with a permanent...
1
by: tian | last post by:
Hi could someone hel me with this dillema. In my current network setup, a certain Access Database(.mdb) File must be opened by two different people at the same time. At this moment in time if one...
2
by: PW | last post by:
Hi, I need to back up the data mdb when our application boots up. I am giong to use a table to make sure the data is backed up whenever the application is started every 5 times (or something...
2
by: Martin | last post by:
From a PHP script, is there any way to retrieve data from an MS Access database that's located on another computer (on a LAN) other than by using ODBC? I posted a question here a couple of weeks...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.