0
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
    Dim cons, query As String
    Dim con As OdbcConnection
    Dim adpt As OdbcDataAdapter
    'Dim num As Integer
    cons = "dsn=Courier; UID=Courier; PWD=123;"
    con = New OdbcConnection(cons)

    con.Open()

    query = "select Name from EMPLOYEE where EMPLOYEE_ID=" + DropDownList1.SelectedValue
    Dim ds As DataSet
    adpt = New OdbcDataAdapter(query, con)
    ds = New DataSet
    adpt.Fill(ds, "Courier")

    ' TextBox1.Text = ds

    con.Close()
End Sub

I want to display the name of the employee in Textbox whoos ID is specified in query, what can I do for that?

1
  • You can start reading some book about .NET programming Commented Sep 20, 2012 at 19:27

2 Answers 2

2

You should use DataRow but to answer your question, try this.

TextBox1.Text = ds.Tables(0).Rows(0)("Name").ToString()
Sign up to request clarification or add additional context in comments.

1 Comment

I think ExecuteScalar is better
0

Since you only want one value back you should skip the dataset and adapter altogether.

query = "select Name from EMPLOYEE where EMPLOYEE_ID=" + DropDownList1.SelectedValue
Dim TempName As String = query.ExecuteScalar
TextBox1.Text = TempName

ExecuteScalar returns the first cell of the first row, that's all you need.

You should read about parameters as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.