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
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