Please help

  • Thread starter Thread starter Gary
  • Start date Start date
G

Gary

Hi all,

I want to bind a Datagrid to Sqlcommand, below is my code

SqlConnection cn = new SqlConnection("Server=winnt;user id =sa;initial

catalog =Northwind");

cn.Open();

SqlCommand cmd = new SqlCommand("select * from employees");

cmd.Connection = cn;

dr = cmd.executereader()

Datagrid1.datasource = dr

Can we bind Datagrid to a command directly or to Data Reader without using

dataAdaptaor ?

TIA,

Gary
 
Hi Gary,
I'm afraid you couldn't do so, because DataSource property of the Datagrid
require the object bind to it has the IListSource interface. However, the
DataReader object doesn't implement such interface.
 
Back
Top