Wednesday, 23 April 2014

How to populate DataGrid from Dataset in Asp.net


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;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

 SqlConnection con = new Sqlconnection("User id =sa; pwd="123" server="ServerName" DataBase="DataBaseName");
          SqlDataAdapter da = new SqlDataAdapter("Select * form employee" ,con);
           DataSet ds = new DataSet();
      da.Fill(ds,"Employee");
dataGrid.DataSource =ds.tables[0].DefaultView;
dataGrid.DataBind();

        }
    }
}

No comments:

Post a Comment