Hers the code that will do the trick for u
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.;Initial Catalog=master;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand("select * from mytable", con);
SqlDataAdapter adp = new SqlDataAdapter();
DataSet ds = new DataSet();
adp.Fill(ds);
DataTable dt = ds.Tables[0];
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read() == true)
{
dataGridView1.DataSource = dt;
}
con.Close();
}
}
}
This is a C# code
Do Rate my answer once u find it useful
Thanks & Regards
Radix :rose:
[edit:rjm]If you must post an answer as code then please use the <pre></pre> tags.[/edit]