C# DataGridView Binding – SQL Server dataset

untitled3.png

using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;

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

private void button1_Click(object sender, EventArgs e)
{

  1.  string str = “select * from Table1 where id between “+pageIndex+” and “+PageSize;
  2.             da = new SqlDataAdapter(str,con);
  3.             ds = new DataSet();
  4.             da.Fill(ds);
  5.             dt = ds.Tables[0];
  6.             bi.DataSource = dt;
  7.             dataGridView1.DataSource = bi;
  8.             dataGridView1.ClearSelection();

}
}
}

Leave a comment