Results 1 to 2 of 2

Thread: get values from sqlserver

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    2

    get values from sqlserver

    Hi everybody,

    I would like to retrieve data from db whenever i click on a button. I have a table for questions and another table for options. I select questions randomly and trying to get the corresponding options but my code below only returns options one time and stays there even though the random number changes. As an example, if random number is 1 i have options a,b,c,d for question 1 and if random number is 2 i have options e,f,g,h for question 2, etc...
    I can't see where i am wrong here. Please help me on that subject.

    Thanks


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Label1.Text = ""
    Label2.Text = ""
    Label3.Text = ""
    Label4.Text = ""

    RandomNumber = RandomClass.Next(1, 4)

    Label5.Text = RandomNumber

    sql = "SELECT option FROM options where question_id=@RandomNumber"
    da = New SqlDataAdapter(sql, con)
    da.SelectCommand.Parameters.Add(New SqlParameter("@RandomNumber", SqlDbType.Int, 10)).Value = Convert.ToInt32(RandomNumber)

    da.Fill(ds, "Options1")

    Label1.Text = ds.Tables("Options1").Rows(0).Item(0)
    Label2.Text = ds.Tables("Options1").Rows(1).Item(0)
    Label3.Text = ds.Tables("Options1").Rows(2).Item(0)
    Label4.Text = ds.Tables("Options1").Rows(3).Item(0)
    da.Dispose()
    sql = ""

    End Sub

  2. #2

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    2

    Re: get values from sqlserver

    I fixed it thank you

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