xml to Database

  • Thread starter Thread starter EDI
  • Start date Start date
E

EDI

I have a XML which needs to be placed into Database. I am using a typed
Dataset and command builder. I loaded the xml into dataset using readXML
method. Now I want to place it into Database. But the rowstate property
remains unchanged because of which Data Adapter is not updating any rows in
the table.

XmlDocument xmlD = new XmlDocument();
xmlD.Load(filePath);

TypedDataSet tds = new TypedDataSet();
tds.Fill(xmlD);

//Here the row status is unchanged.

How do I update rows into database with out having to create a new dataset
and manually load all rows one by one into it?
 
EDI,

Are all of these adds? Depending on the version of .NET that you are
using, you will have two different options available to you.

If you are using .NET 1.1 or before, you will have to create a new data
set, with the same schema, but which is empty. You can then loop through
your loaded data set, calling the AddRow method on the DataRowCollection
returned from the Rows property on the new DataTable. This will cause the
RowState to be Added, which will cause the data adapter to insert new
records into the database.

If you are using .NET 2.0 (the beta), then you can cycle through all the
rows in your loaded table and call the SetAdded method on the row, which
will set the row state to Added, and then run that through the adapter.

Hope this helps.
 
Thank you Nicholas,

I was trying to avoid looping. Now since there is no other way to do that, I
will go ahead with looping. Thank you for your quick response.




Nicholas Paldino said:
EDI,

Are all of these adds? Depending on the version of .NET that you are
using, you will have two different options available to you.

If you are using .NET 1.1 or before, you will have to create a new data
set, with the same schema, but which is empty. You can then loop through
your loaded data set, calling the AddRow method on the DataRowCollection
returned from the Rows property on the new DataTable. This will cause the
RowState to be Added, which will cause the data adapter to insert new
records into the database.

If you are using .NET 2.0 (the beta), then you can cycle through all
the rows in your loaded table and call the SetAdded method on the row,
which will set the row state to Added, and then run that through the
adapter.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

EDI said:
I have a XML which needs to be placed into Database. I am using a typed
Dataset and command builder. I loaded the xml into dataset using readXML
method. Now I want to place it into Database. But the rowstate property
remains unchanged because of which Data Adapter is not updating any rows
in the table.

XmlDocument xmlD = new XmlDocument();
xmlD.Load(filePath);

TypedDataSet tds = new TypedDataSet();
tds.Fill(xmlD);

//Here the row status is unchanged.

How do I update rows into database with out having to create a new
dataset and manually load all rows one by one into it?
 
I generated a typed data set from a table. I am trying to insert a null
value into field of type decimal. Database wont rhow an error. But Dataset
rhows an exception. How do I insert a null value into that field..

I have the following

<xs:element name="XXX" type="xs:decimal" minOccurs="0" nillable="true" />


Nicholas Paldino said:
EDI,

Are all of these adds? Depending on the version of .NET that you are
using, you will have two different options available to you.

If you are using .NET 1.1 or before, you will have to create a new data
set, with the same schema, but which is empty. You can then loop through
your loaded data set, calling the AddRow method on the DataRowCollection
returned from the Rows property on the new DataTable. This will cause the
RowState to be Added, which will cause the data adapter to insert new
records into the database.

If you are using .NET 2.0 (the beta), then you can cycle through all
the rows in your loaded table and call the SetAdded method on the row,
which will set the row state to Added, and then run that through the
adapter.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

EDI said:
I have a XML which needs to be placed into Database. I am using a typed
Dataset and command builder. I loaded the xml into dataset using readXML
method. Now I want to place it into Database. But the rowstate property
remains unchanged because of which Data Adapter is not updating any rows
in the table.

XmlDocument xmlD = new XmlDocument();
xmlD.Load(filePath);

TypedDataSet tds = new TypedDataSet();
tds.Fill(xmlD);

//Here the row status is unchanged.

How do I update rows into database with out having to create a new
dataset and manually load all rows one by one into it?
 
EDI,

Are you trying to do it through code, or through the XML declaration in
the data set?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

EDI said:
I generated a typed data set from a table. I am trying to insert a null
value into field of type decimal. Database wont rhow an error. But Dataset
rhows an exception. How do I insert a null value into that field..

I have the following

<xs:element name="XXX" type="xs:decimal" minOccurs="0" nillable="true" />


Nicholas Paldino said:
EDI,

Are all of these adds? Depending on the version of .NET that you are
using, you will have two different options available to you.

If you are using .NET 1.1 or before, you will have to create a new
data set, with the same schema, but which is empty. You can then loop
through your loaded data set, calling the AddRow method on the
DataRowCollection returned from the Rows property on the new DataTable.
This will cause the RowState to be Added, which will cause the data
adapter to insert new records into the database.

If you are using .NET 2.0 (the beta), then you can cycle through all
the rows in your loaded table and call the SetAdded method on the row,
which will set the row state to Added, and then run that through the
adapter.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

EDI said:
I have a XML which needs to be placed into Database. I am using a typed
Dataset and command builder. I loaded the xml into dataset using readXML
method. Now I want to place it into Database. But the rowstate property
remains unchanged because of which Data Adapter is not updating any rows
in the table.

XmlDocument xmlD = new XmlDocument();
xmlD.Load(filePath);

TypedDataSet tds = new TypedDataSet();
tds.Fill(xmlD);

//Here the row status is unchanged.

How do I update rows into database with out having to create a new
dataset and manually load all rows one by one into it?
 
I am trying using code. But both the ways are fine.
Thanks

Nicholas Paldino said:
EDI,

Are you trying to do it through code, or through the XML declaration in
the data set?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

EDI said:
I generated a typed data set from a table. I am trying to insert a null
value into field of type decimal. Database wont rhow an error. But Dataset
rhows an exception. How do I insert a null value into that field..

I have the following

<xs:element name="XXX" type="xs:decimal" minOccurs="0" nillable="true" />


Nicholas Paldino said:
EDI,

Are all of these adds? Depending on the version of .NET that you are
using, you will have two different options available to you.

If you are using .NET 1.1 or before, you will have to create a new
data set, with the same schema, but which is empty. You can then loop
through your loaded data set, calling the AddRow method on the
DataRowCollection returned from the Rows property on the new DataTable.
This will cause the RowState to be Added, which will cause the data
adapter to insert new records into the database.

If you are using .NET 2.0 (the beta), then you can cycle through all
the rows in your loaded table and call the SetAdded method on the row,
which will set the row state to Added, and then run that through the
adapter.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have a XML which needs to be placed into Database. I am using a typed
Dataset and command builder. I loaded the xml into dataset using readXML
method. Now I want to place it into Database. But the rowstate property
remains unchanged because of which Data Adapter is not updating any rows
in the table.

XmlDocument xmlD = new XmlDocument();
xmlD.Load(filePath);

TypedDataSet tds = new TypedDataSet();
tds.Fill(xmlD);

//Here the row status is unchanged.

How do I update rows into database with out having to create a new
dataset and manually load all rows one by one into it?
 
Back
Top