How to use a value of a datareader?

Discussion in 'ASP .Net' started by Shapper, Jun 3, 2005.

  1. Shapper

    Shapper Guest

    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
     
    Shapper, Jun 3, 2005
    #1
    1. Advertising

  2. 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
    >
    >
     
    =?Utf-8?B?c3Jpbmk=?=, Jun 3, 2005
    #2
    1. Advertising

  3. Shapper

    Shapper Guest

    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" <> wrote in message
    news::

    > 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
    > >
    > >
     
    Shapper, Jun 3, 2005
    #3
  4. 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" <> wrote in message
    > news::
    >
    > > 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
    > > >
    > > >

    >
    >
     
    =?Utf-8?B?c3Jpbmk=?=, Jun 3, 2005
    #4
  5. Shapper

    Shapper Guest

    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



    "srini" <> wrote in message
    news::

    > 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" <> wrote in message
    > > news::
    > >

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

    > >

    >
    > >
     
    Shapper, Jun 3, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rico Alexander
    Replies:
    1
    Views:
    326
    Kevin Spencer
    Oct 17, 2003
  2. Catalin Porancea

    Value from a DataReader to a string

    Catalin Porancea, Nov 10, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    4,459
    vijay
    Nov 10, 2003
  3. Shapper
    Replies:
    1
    Views:
    528
    Lucas Tam
    Apr 22, 2005
  4. tshad
    Replies:
    3
    Views:
    3,866
    tshad
    May 31, 2005
  5. Toska

    Converting datareader value

    Toska, Jun 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    437
    sloan
    Jun 26, 2006
Loading...

Share This Page