Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi

I am trying to retrieve data to the textbox from database.But i am not getting.

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

Dim conStr As String = "Provider=Microsoft.JET.OLEDB.4.0;data source=C:\NWIND.mdb"

 

Dim sqlStr As String = "SELECT * FROM customers"

 

Dim conn As OleDbConnection = New OleDbConnection(conStr)

 

Dim da As OleDbDataAdapter = New OleDbDataAdapter(sqlStr, conn)

 

Dim ds As DataSet = New DataSet()

 

da.Fill(ds, "customers")

 

DataGrid1.DataSource = ds.DefaultViewManager

 

TextBox1.Text = ds!name

 

 

end sub

Posted

First off, a dataset takes on tables from your database and throws them into datatables. You access them via their index like so:

 

ds.Tables(0)

 

or from their tablename if you know it like so:

ds.Tables("Customers")

 

Now, usually a datatable will have mutiple "columns" (or fields) like CustomerID, CustomerName, CustomerShoeSize, etc.

 

On top of this, each table should have 1 or more rows of data, or records.

 

A textbox is only a single field.

 

If you want to display an entire table, you need to use a datagrid by setting its datasource:

 

datagrid.DataSource = ds.Tables("Customers")

 

You can also set a specific field on a specific row into a textbox like so:

 

Textbox.Text = ds.Tables("Customers").Rows(0).Item("CustomerName").ToString()

 

This would set the Textboxes value to the CustomerName Value in row 1 (index of 0) of the Customer Table in your DataSet.

 

If you want to "Browse" your data with navigation controls and changing the text values depending on the index, I'd suggest taking a look at my tutorial (link in my sig)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...