i tried as below its not loading data into grid view when i tried using dataset it worked perfectly
OleDbCommand cmd = new OleDbCommand("select * from customer", con);
con.Open();
MessageBox.Show(con.State.ToString());
OleDbDataReader dr = cmd.ExecuteReader();
con.Close();
MessageBox.Show(con.State.ToString());
dataGridView1.DataSource = dr;
Cheers & thanks everyone

Satyapriya NayakPosted Sep 18, 2013, 9:41 AM
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.SqlClient;
namespace Datareader_datagridview
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"server = HOME-SAT/SQLEXPRESS;data source = .; initial catalog = test; user id=sa;pwd =pintu ;integrated security = SSPI");
SqlCommand com;
string str;
public Form1()
{
InitializeComponent();
}
private void btn_Show_Click(object sender, EventArgs e)
{
try
{
com = new SqlCommand();
com.Connection = con;
com.CommandText = "select * from emp";
con.Open();
SqlDataReader reader = com.ExecuteReader();
if (reader.HasRows)
{
DataTable dt = new DataTable();
dt.Load(reader);
dataGridView1.DataSource = dt;
}
}
finally
{
con.Close();
}
}
}
}
SUNIL GUTTAPosted Sep 18, 2013, 10:12 AM
SUNIL GUTTAPosted Sep 18, 2013, 7:55 AM
Joxin Stanly well you finally binded dataset to dataGrid which i don't want especially , i need Datareader & data grid binding ? .. TY mate
Iftikar HussainPosted Sep 18, 2013, 7:43 AM
Regards,
Iftikar
Joxin StanlyPosted Sep 18, 2013, 6:43 AM
can u plz try something like below -:
SUNIL GUTTAPosted Sep 18, 2013, 6:09 AM
Well tried out ur both ways .. i am just not getting data to dataGridview ??
Problem still persists // in case of dataset its perfect ??
Iftikar HussainPosted Sep 18, 2013, 6:06 AM
try like this
Regards,
Iftikar
Pankaj KumarPosted Sep 18, 2013, 5:51 AM
OleDbCommand cmd = new OleDbCommand("select * from customer", con);
con.Open();
MessageBox.Show(con.State.ToString());
OleDbDataReader dr = cmd.ExecuteReader();
if(dr.HasRows)
{
dataGridView1.DataSource = dr;
}
con.Close();
MessageBox.Show(con.State.ToString());