Nezir Zahirović

Table to XML file C# MSSQL

In this post I will show you pretty simple sample about how you can done fast mssql table export to xml file in c#:
You need simple event where you can put this C# code:

private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "" && textBox2.Text !="" && textBox3.Text != "")
{
string cmd= "Select * from "+textBox3.Text+"";
string conn= textBox2.Text;
DataSet ds = new DataSet();
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd,conn);
da.Fill(ds);
// Write to XML here
ds.WriteXml(textBox3.Text+".xml", XmlWriteMode.WriteSchema);
dataGridView1.DataSource = ds.Tables[0];
}
MessageBox.Show("Uspješno !");
}
SHARE
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment