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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top