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
我想在查询中指定Textbox whoos ID中的员工姓名,我该怎么做?
答案 0 :(得分:2)
你应该使用DataRow但是要回答你的问题,试试这个。
TextBox1.Text = ds.Tables(0).Rows(0)("Name").ToString()
答案 1 :(得分:0)
由于您只需要一个值,因此您应该完全跳过数据集和适配器。
query = "select Name from EMPLOYEE where EMPLOYEE_ID=" + DropDownList1.SelectedValue
Dim TempName As String = query.ExecuteScalar
TextBox1.Text = TempName
ExecuteScalar返回第一行的第一个单元格,这就是你所需要的。
您也应该阅读parameters。