Error populating datagrid from datareader

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I am having problems populating a datagrid from a datareader Here is my code

Dim sqlGetTitleName As String = "Select name from product where supplier = '0064'" '" & SupplierI

Dim odbcConn As OdbcConnection = New OdbcConnection(Configuration.ConfigurationSettings.AppSettings("ConnectString")
Dim odbcCmd1 As OdbcCommand = New OdbcCommand(sqlGetTitleName, odbcConn
Dim drTitleName As OdbcDataReade

odbcConn.Open(

drTitleName = odbcCmd1.ExecuteReade


If Not drTitleName.HasRows The

MessageBox.Show("No Titles found for that vendor"

Exit Su

Els



DataGrid1.DataSource = drTitleNam

' 'CompletionCombo1.Items.Add(drTitleName.GetString(0)



End I

drTitleName.Close(
odbcConn.Close(
 
Chris:

I'm assuming this is for a web app? I don't believe you can bind a
datareader to a grid on the desktop. What's the problem you are having
though? One problem you are having is that you aren't calling
DataGrid.dataBind (if this is a web app). And you'll want to bind the grid
to DataReader.ExecuteReader. Just calling executereader without a While
dr.Read doesn't change the position of the record so binding to it directly
won't do anything. From what I understand, the datagrid.DataSource =
DataReader.ExecuteReader actually does the While dr.Read behind the scenes.
Also, you can still use the if DataReader.HasRows beforehand so you don't
bind to an empty reader.

HTH,

Bill.
 
Hi Chris,

Actualy No,

You can make your own dataadapter using the datareader and than fill a
datatable with that.

Than the answer is Yes.

As far as I know gives that no advantages above using the normal
dataadapter.
(I never have seen one stated that did hold in a discussion).

I hope this gives an idea?

Cor
 
No,unfortunately you can't. You can use a DataTable or a DataSet though.
Chris said:
Hi,
This is for a desktop app. Can I use the dataReader to populate a datagrid
in a desktop app?
 
Back
Top