B
bill
How can I insert a record with a null value in one of the fields?
I need to use the update method from a data adapter. The data is in a XML
file.
I need to use the update method from a data adapter. The data is in a XML
file.
bill said:How can I insert a record with a null value in one of the fields?
I need to use the update method from a data adapter. The data is in a XML
file.
bill said:Thanks Jon
I'm using streamwriter to create a XML file.
Then I use ReadXML to read the XML file into the dataset.
Then I pass the dataset to the data adapter Update method to insert the
data
into the database.
I just don't know what to put between the XML file field tags to indicate
a
null value should be inserted.
It works fine otherwise.
-Bill
Cor Ligthert said:Normally is setting nothing (not the word however really nothing) between
the tags the same as DBnull.value(null).
bill said:Below is a sample of XML which I use for testing. The file name is
"c:\importdemo.xml".
My VB.NET webforms application has a data adapter named SQLDataAdapter1 on
the form which is configured with a SQL statement connection to a table
named tImportData.
This code works fine as long as I don't try to insert a null value in any
fields.
If I put nothing between the XML tags, it inserts an empty string in varchar
fields. In integer fields, there is an error:
System.InvalidCastException: - Cast from string "Input string was not in
a correc" to type Integer is not valid.
Cor Ligthert said:I have it in a program where I delete the empty element tags while writing.
However I have kept open in the reading part that the value is changed and
set empty by hand as well.
I will not say my answer was wrong, however can be confusing and is not
complete, therefore as I have it in that program, with two inline comments
in the confusing part.
It is confusing in VBNet because of the "Is" and "=" nothing and probably
even more confusing in CSharp (just assuming I don't know that) It can be
interesting in my opinion when you show this in CSharp. (velden is an array
of strings with names)
bill said:I tried that and got:
5 prepared statement '(@col1 int,@col2 varchar(25),@col3 nvarchar(10),@'
expects parameter @columnname, which was not supplied
bill said:When I add the SQL Data Adapter to the web forms page, the wizard configures
the update, insert, and delete statements automatically. The insert works
fine if data is included for all fields in the source XML file.
This error occurs if any of the fields are ommitted from the XML source
file.
The database allows nulls in the fields.
bill said:I know it is difficult to identify the problem without seeing the
application.
However, I believe the problem is in the configuration of the SQL Data
Adapter, which is created graphically using the wizard, so I can't provide
that part of the app.
I will re-write the application without using the wizard, instead
instantiating the Data Adapter in code, including the insert statement.
Perhaps this will work! If not, I will post the code on the newsgroup.
Currently, the only written code is
Dim ds as New Dataset
ds.ReadXML("c:\importdemo.xml")
Well, I think your answer *was* wrong, because loading in a dataset
with an empty element inserts an empty string, *not* a DBNull. You can
easily test it for yourself using ReadXml first including an empty tag,
and then not, and using DataRow.IsNull to test for nullity.
Cor Ligthert said:My answer was wrong and than I readed it afterwards wrong myself.
To clear it more,
an item with a dbnull.value will not create an element (node)
a nothing item wil create an empty element (node)
Thanks for showing that.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.