473,666 Members | 2,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.CatalogCla ss cat = new ADOX.CatalogCla ss();//define a Jet database
class
cat.Create("Pro vider=Microsoft .Jet.OLEDB.4.0; " + "Data
Source=history_ data.mdb;" + "Jet OLEDB:Engine Type=5");//create a Jet
database
System.Data.Ole Db.OleDbConnect ion hist_cnn = new
System.Data.Ole Db.OleDbConnect ion();
System.Data.Ole Db.OleDbCommand hist_command = new
System.Data.Ole Db.OleDbCommand ();
hist_command.Co mmandText="CREA TE TABLE hist_data_recor d(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.Connec tionString="Pro vider=Microsoft .Jet.OLEDB.4.0; " + "Data
Source=history_ data.mdb;" + "Jet OLEDB:Engine Type=5";
hist_cnn.Open() ;
hist_command.Co nnection=hist_c nn;
hist_command.Ex ecuteNonQuery() ;
hist_cnn.Close( );

record inersting code:
System.Data.Ole Db.OleDbConnect ion hist_cnn = new
System.Data.Ole Db.OleDbConnect ion();
System.Data.Ole Db.OleDbCommand hist_command = new
System.Data.Ole Db.OleDbCommand ();
System.Data.Dat aSet hist_data = new System.Data.Dat aSet();
hist_command.Co mmandText="inse rt into hist_data_recor d (record_id)
values('2003') ";
hist_cnn.Connec tionString="Pro vider=Microsoft .Jet.OLEDB.4.0; "
+ "Data Source=history_ data.mdb;" + "Jet OLEDB:Engine Type=5";

hist_cnn.Open() ;

hist_command.Co nnection=hist_c nn;

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

Nov 16 '05 #1
1 1895
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******** *****@TK2MSFTNG P09.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.CatalogCla ss cat = new ADOX.CatalogCla ss();//define a Jet database
class
cat.Create("Pro vider=Microsoft .Jet.OLEDB.4.0; " + "Data
Source=history_ data.mdb;" + "Jet OLEDB:Engine Type=5");//create a Jet
database
System.Data.Ole Db.OleDbConnect ion hist_cnn = new
System.Data.Ole Db.OleDbConnect ion();
System.Data.Ole Db.OleDbCommand hist_command = new
System.Data.Ole Db.OleDbCommand ();
hist_command.Co mmandText="CREA TE TABLE hist_data_recor d(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.Connec tionString="Pro vider=Microsoft .Jet.OLEDB.4.0; " + "Data
Source=history_ data.mdb;" + "Jet OLEDB:Engine Type=5";
hist_cnn.Open() ;
hist_command.Co nnection=hist_c nn;
hist_command.Ex ecuteNonQuery() ;
hist_cnn.Close( );

record inersting code:
System.Data.Ole Db.OleDbConnect ion hist_cnn = new
System.Data.Ole Db.OleDbConnect ion();
System.Data.Ole Db.OleDbCommand hist_command = new
System.Data.Ole Db.OleDbCommand ();
System.Data.Dat aSet hist_data = new System.Data.Dat aSet();
hist_command.Co mmandText="inse rt into hist_data_recor d (record_id)
values('2003') ";
hist_cnn.Connec tionString="Pro vider=Microsoft .Jet.OLEDB.4.0; "
+ "Data Source=history_ data.mdb;" + "Jet OLEDB:Engine Type=5";

hist_cnn.Open() ;

hist_command.Co nnection=hist_c nn;

hist_command.Ex ecuteNonQuery() ;//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
2438
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 tb_table when a row with the same int_UID already exists in there. Here is my stored procedure: if not exists (select int_UID from tb_table where int_UID = @aint_UID)
16
17004
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 must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
4
11831
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 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();
0
1522
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 Server myConnection = New SqlConnection("Data Source=SERVER;" _ & "Initial Catalog=database;User Id=user;Password=password;")
0
1266
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 works perfect: records get updated, inserted, deleted without any errors. But if I try to add a record wich offends referential integrity rules defined in the SQL Server 2005 database, the record will not be inserted (which is ok, otherwise the...
6
3450
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 using MS-Access 2000 database table for this app. Note that the datatype of all the fields mentioned above are Text. Apart from the above columns, there's another column in the DB table named 'RegDateTime' whose datatype is Date/Time which is...
0
2145
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 file="../Connections/conn.jsp" %> <% // *** Edit Operations: declare variables // set the form action variable String MM_editAction = request.getRequestURI(); if (request.getQueryString() != null && request.getQueryString().length() > 0) {
0
1309
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 mistake. Thanks. Code: <%@ Page Language="VB" %>
0
1632
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 mistake. Thanks. Code: <%@ Page Language="VB" %>
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8355
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.