ajaymaster1558
asked on
use datareader for binding dataGridView1
i have a table in sql server 2008
i want to bind it using datareader
i want to bind it using datareader
most important point for your feedback: please keep your test/code as simple as possible as to reproduce the problem.
sample code is given below..
using (SqlCommand command = new SqlCommand("select * from YourTable", new SqlConnection("Server=.;Tr usted_Conn ection=Fal se;User ID=xxx;Password=xxxx;Initi al Catalog=DatabaseName")))
{
try
{
command.Connection.Open();
SqlDataReader reader = command.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
}
catch (Exception ex)
{
command.Connection.Close() ;
}
finally
{
command.Connection.Close() ;
}
}
using (SqlCommand command = new SqlCommand("select * from YourTable", new SqlConnection("Server=.;Tr
{
try
{
command.Connection.Open();
SqlDataReader reader = command.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
}
catch (Exception ex)
{
command.Connection.Close()
}
finally
{
command.Connection.Close()
}
}
ASKER
SqlConnection cnsql = new SqlConnection(cnstring);
cnsql.Open();
string sql = "select * from sell";
SqlCommand cmsql = new SqlCommand(sql, cnsql);
SqlDataReader drsql = cmsql.ExecuteReader();
dataGridView1.DataSource = drsql;
this is my code
but it's not work
cnsql.Open();
string sql = "select * from sell";
SqlCommand cmsql = new SqlCommand(sql, cnsql);
SqlDataReader drsql = cmsql.ExecuteReader();
dataGridView1.DataSource = drsql;
this is my code
but it's not work
and what it's your exact error message?
ASKER
not get any error but it not show any data or any thing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
any issue? error messages?