Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am having problem showing the contents of sqldatareader in datagrid. I tried

dataGrid1.DataContext = myReader;
and
dataGrid1.ItemsSource = myReader;

but the I dont see the data, just empty rows

The reader.HasRows is true which tells that it got some rows
Posted

Hello ,

try to put data into a datatable from the sqldatarepeater and then bind that table to grid

hoping it will help you.
thanks
sanjeev
 
Share this answer
 
A DataReader is not an item that you can put into a data context. You need to get the data out of the DataReader and populate proper classes. You bind *that* and not the reader.
 
Share this answer
 
Thanks everyone,
I got the solution. I used SqlDataAdapter

SqlDataAdapter myAdapter = new SqlDataAdapter(selectStr, connString);
DataSet dset = new DataSet();
int i = myAdapter.Fill(dset);
dataGrid1.ItemsSource = dset.Tables[0].DefaultView;

Regards,
Waqas
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900