Update DataBase from xml file
-
Please, I need to know how to read xml document (created with dataSet.WriteXml) with ado.net 2.0 and update the corresponding table in the database with those values. I wrote this test code:
using (DataSet ds = new DataSet()) using (SqlConnection conn = new SqlConnection(connectionString)) using (SqlDataAdapter da = new SqlDataAdapter("select * from TableName", conn)) { try { da.Fill(ds); ds.ReadXml(@"C:\xmldataset.XML"); ds.AcceptChanges(); da.Update(ds); } [...]
Nevertheless, the values in the database haven't been modified, after. What am I missing? Thanks in advance. -
Please, I need to know how to read xml document (created with dataSet.WriteXml) with ado.net 2.0 and update the corresponding table in the database with those values. I wrote this test code:
using (DataSet ds = new DataSet()) using (SqlConnection conn = new SqlConnection(connectionString)) using (SqlDataAdapter da = new SqlDataAdapter("select * from TableName", conn)) { try { da.Fill(ds); ds.ReadXml(@"C:\xmldataset.XML"); ds.AcceptChanges(); da.Update(ds); } [...]
Nevertheless, the values in the database haven't been modified, after. What am I missing? Thanks in advance.Hi, The point you are missing is to insert the data read from XML file. Check this out: http://www.codeproject.com/cs/database/generic_OpenXml.asp[^] http://www.codeproject.com/cs/database/insxmldatasqlsvr.asp[^] http://technet.microsoft.com/en-us/library/ms171806.aspx[^] and also try googling "xml bulk load" Regards, Adeel
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
-
Hi, The point you are missing is to insert the data read from XML file. Check this out: http://www.codeproject.com/cs/database/generic_OpenXml.asp[^] http://www.codeproject.com/cs/database/insxmldatasqlsvr.asp[^] http://technet.microsoft.com/en-us/library/ms171806.aspx[^] and also try googling "xml bulk load" Regards, Adeel
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
Thanks a lot, but I thought the dataset could do it, why is the ReadXml method for then, if you can open the xml like a XmlDocument?
-
Thanks a lot, but I thought the dataset could do it, why is the ReadXml method for then, if you can open the xml like a XmlDocument?
Hi, For knowing that in detail, you may find the following useful: http://msdn2.microsoft.com/en-us/library/system.data.dataset.readxml.aspx[^] http://msdn2.microsoft.com/en-us/library/aa325639(VS.71).aspx[^] Regards, Adeel
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.