473,473 Members | 2,292 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Add Data to SQL

Hey i have the following code below and i get an error
back saying: "An unhandled exception of
type 'System.Data.NoNullAllowedException' occurred in
system.data.dll

Additional information: Column 'ProductID' does not allow
nulls."
I have the same sort of code for an update feature and
delete feature and both work just fine.
The Code:

Private Sub DataAdd()
Dim oAdapter As SqlClient.SqlDataAdapter
Dim oBuild As SqlClient.SqlCommandBuilder
Dim oDR As DataRow
Dim strSQL As String
Dim strConn As String

' Create New DataRow Object From DataSet
oDR = moDS.Tables("Products").NewRow()
oDR.BeginEdit()

' Load new data into row
oDR("ProductName") = txtName.Text
oDR("SupplierID") = CType
(cboSupplier.SelectedItem, _
PDSAListItemNumeric).ID
oDR("CategoryID") = CType
(cboCategory.SelectedItem, _
PDSAListItemNumeric).ID
oDR("QuantityPerUnit") = cboSupplier.Text
oDR("UnitPrice") = CDec(txtPrice.Text)
oDR("UnitsInStock") = CShort(txtInStock.Text)
oDR("UnitsOnOrder") = CShort(txtOnOrder.Text)
oDR("ReorderLevel") = CShort(txtReorder.Text)
oDR("Discontinued") = CBool(chkDisc.Checked)

' Tell DataRow you are done adding data
oDR.EndEdit()
' Add DataRow to DataSet
moDS.Tables("Products").Rows.Add(oDR)

Try
' Get Connection String
strConn = ConnectStringBuild()
' Build SQL String
strSQL = "SELECT * FROM Products "
' Create New DataAdapter
oAdapter = _
New SqlClient.SqlDataAdapter(strSQL, strConn)
' Create CommandBuilder for Adapter
' This will build INSERT, UPDATE and DELETE
SQL
oBuild = New SqlClient.SqlCommandBuilder
(oAdapter)

' Get Insert Command Object
oAdapter.InsertCommand =
oBuild.GetInsertCommand()

' Submit INSERT statement through Adapter
oAdapter.Update(moDS, "Products")
' Tell DataSet changes to data source are
complete
moDS.AcceptChanges()

' Reload the list box
ListLoad()

Catch oException As Exception
MessageBox.Show(oException.Message)

End Try
End Sub
Nov 20 '05 #1
2 2250
Cor
Hi Trevor,

Additional information: Column 'ProductID' does not allow
nulls."

I think that the reason for the error is given, you have made your database
in a way that the "ProductID" has to be given in a row, and I thought to see
in your code that you did not.

I hope this helps a 1/8 byte?

Cor
Nov 20 '05 #2
* "Trevor" <tj**@bigpond.net.au> scripsit:
Hey i have the following code below and i get an error
back saying: "An unhandled exception of
type 'System.Data.NoNullAllowedException' occurred in
system.data.dll


ADO.NET group:

<news://msnews.microsoft.com/microsoft.public.dotnet.framework.adonet>

Web interface:

<http://msdn.microsoft.com/newsgroups/default.asp?url=/newsgroups/loadframes.asp?icp=msdn&slcid=us&newsgroup=microso ft.public.dotnet.framework.adonet>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

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

Similar topics

3
by: Chris | last post by:
Could someone please provide me an effective means of exporting data from a data set (or data grid) to Excel?
9
by: Tony Lee | last post by:
Some time a ago, on this newsgroup the following comments were made in recommending good references for Access (2003) >I used to recommend Dr. Rick Dobson's, "Programming Access <version>" for...
1
by: djozy | last post by:
Please, I want to insert data into SQL Server database. I know for this commmand: SqlCommand myCommand= new SqlCommand("INSERT INTO table (Column1, Column2) " + "Values ('string', 1)",...
1
by: T8 | last post by:
I have a asp.net (framework 1.1) site interfacing against SQL 2000. It runs like a charm 99% of the time but once in a while I get the following "unspecified error". Sometimes it would resolve by...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
3
by: bbernieb | last post by:
Hi, All, Is it possible to access a variable inside of a data binding, without the variable being out of scope? (Note: On the DataBinder line, I get an error message that says "Name 'i' is...
5
by: Gene | last post by:
What can I do if I want to get the result using the sql command? for example, the select command is "select Name from Employee where StaffID=10" How to get the "Name"??? dim Name as string and...
5
by: DC Gringo | last post by:
I am having a problem reading a simple update to the database. Basically I'm testing a small change to the pubs database -- changing the price of the Busy Executive's Database Guide from 19.99 to...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
0
by: Winder | last post by:
Computer Data Recovery Help 24/7 Data recovering tools and services is our focus. We will recover your data in a cost effective and efficient manner. We recover all operating systems and media....
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...
1
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
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.