Friday 13 December 2013

Datatable To XML string in .net Using Gridview

I have Used a data Gridview to make my own  edited xml string which I will use in SQL server stored procedure as argument .
Now the code is here :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        DataTable DT = new DataTable();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            DT.Columns.Add("Name", typeof(string));
            DT.Columns.Add("Phone", typeof(string));
            DT.Columns.Add("Address", typeof(string));
            dataGridView1.DataSource = DT;
        }

        private void btnXml_Click(object sender, EventArgs e)
        {
            DataSet DS = new DataSet();
            DS.Tables.Add(DT);
            MessageBox.Show(DS.GetXml());
        }
    }
}




The result will be in XML

After this how you will use this XML string in SQL server that you can find in my article Using XML string in Stored Procedure(SP) in Sql Server


No comments:

Post a Comment