# Fill in Textboxes from a Dataset

**URL:** <https://forums.thehomestack.io/t/fill-in-textboxes-from-a-dataset/102>\
**Category:** vb.Net\
**Created:** [December 27, 2003, 6:10pm UTC](https://forums.thehomestack.io/t/fill-in-textboxes-from-a-dataset/102 "2003-12-27T18:10:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![robinhood1995](https://forums.thehomestack.io/letter_avatar_proxy/v4/letter/r/48db29/32.png) [@robinhood1995](https://forums.thehomestack.io/u/robinhood1995)\
**Post date:** [December 27, 2003, 6:10pm UTC](https://forums.thehomestack.io/t/fill-in-textboxes-from-a-dataset/102/1 "2003-12-27T18:10:27Z")

</div>

Dim CON As New SqlClient.SqlConnection  
CON.ConnectionString = “integrated security=SSPI;data source=SERVER1;persist security info=False;initial catalog=filmtrack”

```
    Dim ds As New DataSet 
    Dim da As New SqlClient.SqlDataAdapter("SELECT JobNo, BoxNo,PartJob FROM JobTab WHERE JobNo LIKE '%" & TextBox1.Text & "%'", CON) 

    ds.Clear() 
    CON.Open() 

```

da.Fill(ds)

If ds.Tables(0).Rows.Count \>0 Then  
TextBox2.Text = ds.Tables(0).Rows(0)(“PartJob”)  
TextBox3.Text = ds.Tables(0).Rows(0)(“BoxNo”)  
End If

---

<div class="post-metadata">

**Author:** ![system](https://forums.thehomestack.io/uploads/default/original/1X/161426793bc0d8bdf0d1a6692b3e44446861cc72.jpeg) [@system](https://forums.thehomestack.io/u/system)\
**Post date:** [January 2, 2004, 6:36am UTC](https://forums.thehomestack.io/t/fill-in-textboxes-from-a-dataset/102/2 "2004-01-02T06:36:11Z")

</div>

You could also do the following:  
This number is to select 1 row. For example when you put a value in textbox is just 1 values. So you choose the row number and take from there.

If you want to bind a listbox or a combobox to a dataset you dont have to do it.  
You can do that 2 ways:

1 -automatic

listbox1.DataSource = ds.tablename  
listbox1.DisplayMember = “columnname”

2 - loop the dataset

Dim i as Integer  
For i = 0 to ds.tablename.Rows.Count -1  
ListBox1.Items.Add(ds.tablename.Rows(i)(“columnname”))  
Next

Once you filled the dataset you do the event handle:

Private Sub ListBox1\_SelectedvalueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedValueChanged  
TextBox1.Text = ListBox1.SelectedText  
End Sub
