Dataset items to variables !!! URGENT!!!

Discussion in 'ASP .Net Web Controls' started by Michael Persaud, Oct 5, 2004.

  1. Hi All,
    I am trying to write the contents of a dataset to variables that i have
    declared as string types.

    I cannot seem to get it right to assign the field values to the variables

    Pls Help
    Thanks
    MP

    Sub getuserDetails()
    Dim str As String = "Select Address,City,Telephone,Alternatetele
    from ContactDetails where userid=" & LabelUserID.Text
    Dim cmdText As New SqlCommand(str, Conn)
    Dim ds As New DataSet
    Dim da As SqlDataAdapter = New SqlDataAdapter(cmdText)
    Conn.Open()
    da.Fill(ds, "ContactDetails")

    Conn.Close()

    UAddress = ds.Tables("ContactDetails").Rows(1).Item(0).ToString

    UCity = ds.Tables("ContactDetails").Rows(1).Item(0).ToString
    ...............................
    Michael Persaud, Oct 5, 2004
    #1
    1. Advertising

  2. Michael Persaud

    Eric Cherng Guest

    Are you sure there are items returned? Are there any exceptions thrown?

    Btw, I'm assuming you know that the SQL code you posted is susceptible to
    SQL injection attack. I hope you just did that to show the code and isn't
    the actual code.

    --
    Eric Cherng
    MCP, MCDBA, MCSD
    http://echerng.com


    "Michael Persaud" <> wrote in message
    news:...
    > Hi All,
    > I am trying to write the contents of a dataset to variables that i have
    > declared as string types.
    >
    > I cannot seem to get it right to assign the field values to the variables
    >
    > Pls Help
    > Thanks
    > MP
    >
    > Sub getuserDetails()
    > Dim str As String = "Select Address,City,Telephone,Alternatetele
    > from ContactDetails where userid=" & LabelUserID.Text
    > Dim cmdText As New SqlCommand(str, Conn)
    > Dim ds As New DataSet
    > Dim da As SqlDataAdapter = New SqlDataAdapter(cmdText)
    > Conn.Open()
    > da.Fill(ds, "ContactDetails")
    >
    > Conn.Close()
    >
    > UAddress = ds.Tables("ContactDetails").Rows(1).Item(0).ToString
    >
    > UCity = ds.Tables("ContactDetails").Rows(1).Item(0).ToString
    > ..............................
    >
    >
    Eric Cherng, Oct 6, 2004
    #2
    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. Gilles Kuhn
    Replies:
    0
    Views:
    436
    Gilles Kuhn
    Sep 15, 2003
  2. Bart Van Hemelen
    Replies:
    2
    Views:
    4,667
    Bart Van Hemelen
    Sep 4, 2006
  3. Larry Bud
    Replies:
    13
    Views:
    7,679
    Larry Bud
    Jan 7, 2008
  4. Ben
    Replies:
    2
    Views:
    884
  5. Replies:
    9
    Views:
    942
Loading...

Share This Page