• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 590
  • Last Modified:

DataTable.Insert and null values.

Hey there guys,
I am trying to do a insert into the database used the insert property generated by my xsd in visual studio.

CustomerData.Insert(FName, LName, BillAddress, BillCity, BillState, BillZip, Phone, CompName, Email, null, null, null, null, null, 0);

As you can see i am trying to pass null values on some of the comulns. The database allows nulls in these fields, the columns in the TableAdapter in my xsd file allows nulls, the AllowDBNull property of these fields is set to true. yet i am still getting a error when trying to pass these nulls.
------------------------------------------------------------------------------------------
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: FLD_COMMENTS
Source Error:

Line 7258:            }
Line 7259:            if ((FLD_COMMENTS == null)) {
Line 7260:                throw new System.ArgumentNullException("FLD_COMMENTS");
Line 7261:            }
Line 7262:            else {
---------------------------------------------------------------------------------------

Am i missing something here?

Nugs
0
Nugs
Asked:
Nugs
  • 2
2 Solutions
 
surajgupthaCommented:
Try settting it as DBNUll.value instead of null
0
 
JimBrandleyCommented:
A null in the DB and a null in C# are two different beasts. If you want to insert a null, set the value for that parameter to:

System.DBNull

Jim
0
 
NugsAuthor Commented:
MSDN does not say that:
http://msdn2.microsoft.com/en-us/library/ms364060(vs.80).aspx

" The EmployeeID and OrderDate columns are both type Nullable because the corresponding columns in the Northwind database allow nulls. You can call the Insert function passing Nothing (null in C#) in the place of type-safe parameters instead of setting a separate property or using another bulky mechanism to indicate that the fields are null. "
0
 
NugsAuthor Commented:
Something wierd was happening here, i do not thin the changes and updates to my XSD file were being saved but i was able to fix this and am able to pass null as a value into these fields

CustomerData.Insert(FName, LName, BillAddress, BillCity, BillState, BillZip, Phone, CompName, Email, null, null, null, null, null, 0);

thanks for the input guys

Nugs
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now