User-939850651 posted
Hi vj78,
If you want to bind the queried data to a TextBox, you need to fill the data into a DataSet or DataTable, and then get them based on the column name.
Here is a simple example based on the code you provided:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Search(1)
End Sub
Private Sub Search(StaffID As String)
Dim conn As New SqlConnection
Dim strConnString As String
strConnString = ConfigurationManager.ConnectionStrings("conStr").ToString()
Try
conn.ConnectionString = strConnString
conn.Open()
Dim cmdtText As String = "SELECT StaffID, StaffFName, StaffLName, StaffCity FROM Staff WHERE StaffID = 1"
Dim ds As New DataSet
Dim cmde As New SqlCommand(cmdtText, conn)
Dim da As New SqlDataAdapter(cmde)
da.Fill(ds) 'Fill select data to DataSet or DataTable
cmde.CommandType = CommandType.Text
cmde.CommandText = cmdtText
cmde.Connection = conn
cmde.ExecuteNonQuery()
txtID.Text = ds.Tables(0).Rows(0).Field(Of Integer)("StaffID").ToString() 'Column name => StaffID
txtFName.Text = ds.Tables(0).Rows(0).Field(Of String)("StaffFName").ToString() 'Column name => StaffFName
conn.Close()
Catch ex As SqlException
messagebox.Text = ("Load Course Details:" & ex.Message)
End Try
End Sub
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" ID="txtID"></asp:TextBox>
<br /><br />
<asp:TextBox runat="server" ID="txtFName"></asp:TextBox>
<br /><br />
<asp:Label runat="server" ID="messagebox"></asp:Label>
</div>
</form>
Result:

Hope this can help you.
Best regards,
Xudong Peng