Results 1 to 3 of 3

Thread: Refering to fields in dataset

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Refering to fields in dataset

    Below is a small chunk of code I use to validate a login form (usernam and password).

    if userDS.Tables(0).rows.count > 0 then
    'username and password exist
    response.Clear()
    response.redirect ("admin_main.aspx")
    else
    msg.text = "Invalid entry: Please try again"
    end if

    Once a user is verified, before the response.redirect I would like to create sessions for a variety of fields held in the dataset e.g fldUsername, fldPassword, fldTelephone.
    Creating the sessions is not the problem but refering to the fields in the dataset is. I am to accustomed to classic ASP and am just learning the scary .net monster.

    Can anyone help please?

    Thankyou

    Parksie

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    In this situation I'd use a DataReader, it's faster. But to answer your question, you could do this:
    VB Code:
    1. YourDataSet.Tables(0).Rows(0)("YourField").ToString()
    ... with a DataReader
    VB Code:
    1. Dim connString As String = "your connection string"
    2. Dim cn As New SqlConnection(connString)
    3. Dim cmdText As String = "Select * From Users Where ..."
    4. Dim cmd As New SqlCommand(cmdText, cn)
    5. Dim dr As SqlDataReader
    6.  
    7. cmd.Connection.Open()
    8. dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
    9. If dr.Read() Then
    10.   Session("YourColumn") = dr("YourColumn").ToString()
    11.   Response.Redirect("yourPage.aspx")
    12. Else
    13.   msg.Text = "Login Failed"
    14. End If

  3. #3

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    Thanks pvb.

    I hope santa fills your sack.


    Parksie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width