By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,372 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.