Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > populate datagrid with datareader in vb.net
 

populate datagrid with datareader in vb.net

hello everybody
 iam unable to populate datagrid with datareader object in vb.net
i am not interested in using dataset
the following code is not working
datagrid1.datasource=datareader
datagrid1.databind
Pradeep Gupta  Thursday, September 08, 2005 6:58 PM

The Windows Forms DataGrid has a different requirement than the Web Forms one: you need to be able to get data at a given row (IList) instead of just read it through forward once (IEnumerable, which is what DataReader is).  One way around this is to use BindingSource, which will read the data out:
  Dim source As New BindingSource
  source.DataSource = datareader
  datagrid1.DataSource = source

-Scott

Scott Berry  Thursday, September 22, 2005 5:41 PM

The Windows Forms DataGrid has a different requirement than the Web Forms one: you need to be able to get data at a given row (IList) instead of just read it through forward once (IEnumerable, which is what DataReader is).  One way around this is to use BindingSource, which will read the data out:
  Dim source As New BindingSource
  source.DataSource = datareader
  datagrid1.DataSource = source

-Scott

Scott Berry  Thursday, September 22, 2005 5:41 PM

Hi Scott, but I found BinidingSource is part of framework 2.0, Is there any alternative way in 1.1 to achieve the same.

-prince

Prince Chalakkal  Friday, September 23, 2005 1:59 PM
Hi Scott,
I am using the Vs 2008. i tryed what you have mention in the above.but i am getting error.Bellow i have mentioned my code.

SqlConnection con = new SqlConnection("SERVER=.;UID=sa;PWD=123;DATABASE =NorthWind");

con.Open();

SqlCommand objCommand = new SqlCommand("SELECT FirstName, LAstName from Employees",con);

sqlDataReader = objCommand.ExecuteReader(System.Data.

CommandBehavior.CloseConnection);

BindingSource bindingSource = new BindingSource();

bindingSource = sqlDataReader;

/// Here i am getting error "Can not implicity convert type"

this.dataGridT1.DataSource = sqlDataReader;


-Balamurugan.S

Balupad  Sunday, July 19, 2009 9:38 AM

You can use google to search for other answers

Custom Search

More Threads

• Populating method of dataGridView
• DataBindings
• ADO.NET Constraints and Referential Integrity
• How to Truncate Time from DateTime in a DataTable object
• Reading Values from app.config
• How do I hide the location bar in a pop up window using window.showModalDialog?
• how can i write in the file
• how to edit datagridview's column
• How do i stop datagridview from resetting its current view?
• Vertical Alignment of column headers