XML to database

E

eulalie

Hi,

I would like to read/write xml file from/to database

I have build a database in microsoft sqlserver manegement studio and i
have defined
a table called 'test' in wich i have a field 'xml' of xml type

I want now from my application ( c# ) to write ( then read ) into this
database

When i debug this i've got no error but the field is not update at all

Can you give me the code to read and write xml files into a sqlserver
database


System.Data.SqlClient.SqlConnection con = new
System.Data.SqlClient.SqlConnection(SqlDataSource2.ConnectionString);
con.Open();

string sql = "select * from test where name = ''" + xmlFile +
"'";

System.Data.SqlClient.SqlDataAdapter dataAdpater = new
System.Data.SqlClient.SqlDataAdapter(sql, con);
dataAdpater.UpdateCommand = new
System.Data.SqlClient.SqlCommand("UPDATE test SET xml = @xml WHERE name
= ''" + xmlFile + "'", con);

System.Data.SqlClient.SqlParameter parameter =
dataAdpater.UpdateCommand.Parameters.Add(
"@xml", SqlDbType.Xml);
parameter.SourceColumn = "variables";
parameter.SourceVersion = DataRowVersion.Original;

System.Data.DataSet ds = new System.Data.DataSet();
dataAdpater.Fill(ds, "test");

DataRow row = ds.Tables["test"].Rows[0];
row["xml"] = ds.ReadXml(xmlFile);

dataAdpater.Update(ds, "test");

con.Close();

Thank you
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top