How to use a value of a datareader?

S

Shapper

Hello,

I have created a datareader function in a asp.net/vb web site.

The datareader returns only one record with 2 fields:
[message] and [imageURL]

In the same aspx.vb I want to use this values as follows:
myImage.ImageURL = [ image URL ]
myImage.Text = [ message ]

How can I do this?

Thanks,
Miguel
 
G

Guest

try using
myImage.ImageURL =dr.Item("imageURL").ToString()
myImage.Text = dr.Item("message").ToString()

where dr is your datareader.
 
S

Shapper

Hello,

I am using this:
drMessage(error_code).Item("icon_URL").ToString()

I get the error:
System.InvalidOperationException: No data exists for the row/column.

I tested the datareader and it's working fine.
The variable error_code filters the right record.

What is wrong here?

Thanks,
Miguel

try using
myImage.ImageURL =dr.Item("imageURL").ToString()
myImage.Text = dr.Item("message").ToString()

where dr is your datareader.

--
HTH
srini
http://www.expertszone.com


:

Hello,

I have created a datareader function in a asp.net/vb web site.

The datareader returns only one record with 2 fields:
[message] and [imageURL]

In the same aspx.vb I want to use this values as follows:
myImage.ImageURL = [ image URL ]
myImage.Text = [ message ]

How can I do this?

Thanks,
Miguel
 
G

Guest

hi,
datareader always holds only one record. and when you say
drMessage(error_code) its actually looking for a column with column name
[error_code] which is obviously not there. you have to loop through the
records in the datareader to check for the record corresponding to that error
code. instead why dont you consider sending the [error code] in the query or
storedproc and get the corresponding record(filter at the database itself).
--
HTH
srini
http://www.expertszone.com


Shapper said:
Hello,

I am using this:
drMessage(error_code).Item("icon_URL").ToString()

I get the error:
System.InvalidOperationException: No data exists for the row/column.

I tested the datareader and it's working fine.
The variable error_code filters the right record.

What is wrong here?

Thanks,
Miguel

try using
myImage.ImageURL =dr.Item("imageURL").ToString()
myImage.Text = dr.Item("message").ToString()

where dr is your datareader.

--
HTH
srini
http://www.expertszone.com


:

Hello,

I have created a datareader function in a asp.net/vb web site.

The datareader returns only one record with 2 fields:
[message] and [imageURL]

In the same aspx.vb I want to use this values as follows:
myImage.ImageURL = [ image URL ]
myImage.Text = [ message ]

How can I do this?

Thanks,
Miguel
 
S

Shapper

Hi,

Maybe we are thinking differently. My function already returns all the
records according to error_code.

I used inserted a datagrid on my aspx page and the record is displayed.

I send you my drMessage function which returns the record:

Function drMessage(ByVal message_code As String) As
System.Data.IDataReader
Dim connectionString As String =
System.Configuration.ConfigurationSettings.AppSettings("connectionString")
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "SELECT [t_4web_message].* FROM
[t_4web_message] WHERE ([t_4web_message].[message_"& _
"code] = @message_code)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_message_code As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_message_code.ParameterName = "@message_code"
dbParam_message_code.Value = message_code
dbParam_message_code.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_message_code)

dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

Return dataReader
End Function

So when I do drMessage("404") I get the right record.
Now instead of displaying all fields in a dataset I just want to make
access one of the fields to use as an imageURL and the other field to
use as text message.

Thanks,
Miguel



hi,
datareader always holds only one record. and when you say
drMessage(error_code) its actually looking for a column with column name
[error_code] which is obviously not there. you have to loop through the
records in the datareader to check for the record corresponding to that error
code. instead why dont you consider sending the [error code] in the query or
storedproc and get the corresponding record(filter at the database itself).
--
HTH
srini
http://www.expertszone.com


:

Hello,

I am using this:
drMessage(error_code).Item("icon_URL").ToString()

I get the error:
System.InvalidOperationException: No data exists for the row/column.

I tested the datareader and it's working fine.
The variable error_code filters the right record.

What is wrong here?

Thanks,
Miguel

try using
myImage.ImageURL =dr.Item("imageURL").ToString()
myImage.Text = dr.Item("message").ToString()

where dr is your datareader.

--
HTH
srini
http://www.expertszone.com


:


Hello,

I have created a datareader function in a asp.net/vb web site.

The datareader returns only one record with 2 fields:
[message] and [imageURL]

In the same aspx.vb I want to use this values as follows:
myImage.ImageURL = [ image URL ]
myImage.Text = [ message ]

How can I do this?

Thanks,
Miguel
 

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

Members online

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top