CygNuS
Well-known member
Ok i'm having the weirdest problem with inserting records which can contain NULL values.
I will try to explain:
I'm using a dataadapter and dataset to insert my records into the SQL 2005 database.
I've also written my own Insert statement for the dataadapter to use (i really need to do this)
this insert statement contains a parameter @INTRASTATNUMMER
This field can contain Null-values (System.DBNull)
I added watches on every record in my dataset:
Dataset_byref.Tables("BONDETAIL").Rows(0).Item("INTRASTATNUMMER") _________"0101.1010"
Dataset_byref.Tables("BONDETAIL").Rows(1).Item("INTRASTATNUMMER") _________{System.DBNull}
Dataset_byref.Tables("BONDETAIL").Rows(2).Item("INTRASTATNUMMER") _________{System.DBNull}
Now just after i run the Update command of my dataadaptor...
...This is the watch on my parameter:
DataAdaptor_byref.InsertCommand.Parameters.Item("@INTRASTATNUMMER").Value ________"" {String}
This means that the @INTRASTATNUMMER parameter for the last record of my dataset (containing the System.DBNull value) is suddenly changed to an empty string "".
So the dataadapter tries to insert the records containing INTRASTATNUMMER "0101.1010", <NULL> and "".
I really need INTRASTATNUMMER in that last record to be NULL because "" violates a Foreign Key.
What am i doing wrong?
The VERY weird thing is that System.DBNULL is ALWAYS ONLY converted to "" if it is in THE LAST RECORD in my dataset. Why?
I will try to explain:
I'm using a dataadapter and dataset to insert my records into the SQL 2005 database.
I've also written my own Insert statement for the dataadapter to use (i really need to do this)
this insert statement contains a parameter @INTRASTATNUMMER
VB.NET:
cmd_insertbonD.Parameters.Add("@INTRASTATNUMMER", SqlDbType.NVarChar, 9)
cmd_insertbonD.Parameters("@INTRASTATNUMMER").SourceColumn = "INTRASTATNUMMER"
I added watches on every record in my dataset:
Dataset_byref.Tables("BONDETAIL").Rows(0).Item("INTRASTATNUMMER") _________"0101.1010"
Dataset_byref.Tables("BONDETAIL").Rows(1).Item("INTRASTATNUMMER") _________{System.DBNull}
Dataset_byref.Tables("BONDETAIL").Rows(2).Item("INTRASTATNUMMER") _________{System.DBNull}
Now just after i run the Update command of my dataadaptor...
VB.NET:
[SIZE=2]DataAdaptor_byref.Update(Dataset_byref, "BONDETAIL")[/SIZE]
...This is the watch on my parameter:
DataAdaptor_byref.InsertCommand.Parameters.Item("@INTRASTATNUMMER").Value ________"" {String}
This means that the @INTRASTATNUMMER parameter for the last record of my dataset (containing the System.DBNull value) is suddenly changed to an empty string "".
So the dataadapter tries to insert the records containing INTRASTATNUMMER "0101.1010", <NULL> and "".
I really need INTRASTATNUMMER in that last record to be NULL because "" violates a Foreign Key.
What am i doing wrong?
The VERY weird thing is that System.DBNULL is ALWAYS ONLY converted to "" if it is in THE LAST RECORD in my dataset. Why?
Last edited: