473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

How to use a value of a datareader?

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

Nov 19 '05 #1
4 4306
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
"Shapper" wrote:
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

Nov 19 '05 #2
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

"srini" <sr***@discussions.microsoft.com> wrote in message
news:sr***@discussions.microsoft.com:
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
"Shapper" wrote:

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


Nov 19 '05 #3
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" wrote:
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

"srini" <sr***@discussions.microsoft.com> wrote in message
news:sr***@discussions.microsoft.com:
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
"Shapper" wrote:

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


Nov 19 '05 #4
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.AppSett ings("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.CommandBehavio r.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

"srini" <sr***@discussions.microsoft.com> wrote in message
news:sr***@discussions.microsoft.com:
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" wrote:

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

"srini" <sr***@discussions.microsoft.com> wrote in message
news:sr***@discussions.microsoft.com:

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
"Shapper" wrote:

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
>
>



Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: ALI-R | last post by:
Hi All, First of all I think this is gonna be one of those threads :-) since I have bunch of questions which make this very controversial:-0) Ok,Let's see: I was reading an article that When...
3
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They...
3
by: catweezle2010 | last post by:
Hello NG, I have three files (default.aspx, search.aspx and work.aspx). The way is: login on default (if session is newsession). The loginname I write into as sessionvariable (username). So I...
0
by: JJ_377 | last post by:
The following doesn't assign value to the dropdownlist - WHY? ___________________________________________________________________ In a user control (ascx named USACustomer) : Public Property...
4
by: Learner | last post by:
Hello, This my a method to call a stored proce and uses a DataReader to read the data in the below method I am trying to assign a null value to my datareader variable Dim datareader As...
2
by: RSH | last post by:
I have a situation where I am looping through a datareader's rows. An exception is being generated when I attempt to check the value of a Boolean field where it has a null value:\ If...
2
by: bh | last post by:
Is there such thing as a default exception value? I'm trying to pass an optional parameter, containing an exception back to a calling procedure. In the pseudocode, below, what might I put in...
2
by: Vahagn | last post by:
Hi, how do I retrieve the chosen value from a RadioButtonList? I have a RadioButtonList that is populated dynamically with a "Next" button. Ie, I have a list of questions each with 2-3 answer...
5
by: axapta | last post by:
Hi Group, How can I overcome the issue of null values in a datareader. I keep getting the dbnull error when I try to assign a null value to a text box. TIA
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.