|
 |
aspdotnet_website_programming thread: Re: Datagrid question
Message #1 by "Larkin Young" <youngld@j...> on Fri, 1 Nov 2002 00:53:56
|
|
> Hi
> I am reading one record from a database, based on a customer name
selected
b> y the customer from a dropdown list. When the Search button is
clicked, I
w> ant to pull back other information (Phone, Fax, Account Number) from
the
d> atabase for that customer and display the results on my web form.
> I've tried a mixture of different things but am getting more confused
as I
g> o. Any help would be great.
> This is where I've got to so far, now I can't figure out how to access
the
i> nformation in myReader.
>
D> im oConn As New OdbcConnection("DSN=Ulysses")
> Dim oCMD As OdbcCommand = New OdbcCommand("SELECT CUSTOMER_NAME, PHONE,
F> AX, ACCOUNT_NO FROM CUSTOMER WHERE CUSTOMER_NAME = '" &
l> stCustName.SelectedItem.Value & "'", oConn)
> oConn.Open()
> Dim myReader As OdbcDataReader = oCMD.ExecuteReader
> Please help!
J> ennie.
Hey Jennie,
There are 2 ways you can do this..you can either do something like
myReader.GetValue(0) to get the value at that ordinal(index) in the
datareader --the ordinal is dictated by the order in which you specified
the columns in the select statement i believe. Of course with this method
you have to then cast the returned objects to their respective datatypes
explicitly. Or, you can use myReader.GetInt32(0) to get the first column
value, and this returns it as the native data type so you don't need to
explicitly cast it. Hope this helps you, let me know if you have any
other questions.
-Larkin Young
Senior, Computer Science
James Madison University
Message #2 by "Jennie Frizelle" <jfrizelle@d...> on Tue, 5 Nov 2002 10:27:35
|
|
Hi Larkin,
Thanks for your help. However, I'm still having problems - probably doing
something silly, but I can't see what it is.
I'm trying to print the values from myReader directly onto the page now
(it doesn't matter whether they go into a datagrid or not, that was an
initial idea) using the following code :
Response.Write (myReader.GetValue(0))
I've also tried .GetInt32(0) and .GetString(0), and tried (1) for each
combination, but I just keep getting the error "No Data found for Row/Col".
I know it's reading the info correctly, as I can populate a listbox with a
value as follows :
lstDetails.DataSource = myReader
lstDetails.DataTextField = "ACCOUNT_NO"
lstDetails.DataValueField = "ACCOUNT_NO"
lstDetails.DataBind()
It puts the correct account_no (or phone / fax / whatever I specify) into
the list box.
Thanks again,
Jennie.
|
|
 |