473,396 Members | 2,098 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,396 software developers and data experts.

insert a record rise an exception

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

Nov 16 '05 #1
1 1882
You are getting an error because you are creating a table where each row
must have seven values... you defined each value as NOT NULL, which means
that you WANT the database to throw an error and reject any record where any
of the seven columns is null.

Then, you use an insert statement that only has one value. The rest of the
values are null.
The database is responding with an error, just like you told it to.

Either pass values for the other fields, or define the table so that the
other values are allowed to be stored as null. (Do what makes sense for
your application).

--- Nick

"authorking" <au************@hotmail.com> wrote in message
news:uw*************@TK2MSFTNGP09.phx.gbl...
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

Nov 16 '05 #2

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

Similar topics

3
by: Suzanne | last post by:
Hi All I'm having problems getting my data adapter to throw a concurrency exception with an INSERT command. I want to throw a concurrency exception if an attempt is made to enter a row into...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
4
by: authorking | last post by:
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...
0
by: Eustice Scrubb | last post by:
In line coding problem. Here's my code: <script language="VB" runat="server"> Dim myConnection As SqlConnection Sub Page_Load(Src As Object, e As EventArgs) ' Create a connection to the SQL...
0
by: Curious Trigger | last post by:
Hi NG, in my asp.net page a DetailView-Control is bound to a DataSource-Control with select, insert, update and delete-commands configured. As long as I type valid data into the DetailView all...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
0
ak1dnar
by: ak1dnar | last post by:
There is a Error getting while i am entering records using this jsp file. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %> <%@ include...
0
by: Michael | last post by:
I know I am missing something simple, but I am stuck. When I submit the following for the employee info gets stored in scale1 and scale1 shows the employee number. Can someone show me my...
0
by: bgreer5050 | last post by:
I know I am missing something simple, but I am stuck. When I submit the following for the employee info gets stored in scale1 and scale1 shows the employee number. Can someone show me my...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.