• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Howto: Fill some textboxes using a dataset

I'm trying the fill some textboxes with data from a dataset - code below. It keeps telling that table 0 doesn't exist. Is there a better way to fill these textboxes than the way I'm going at it?


Dim MyConn As New Data.OleDb.OleDbConnection(gstr_ConnString)

strSQL = "Select * From tbl_Unit WHERE Unit_AutoID ='" & g_lng_AutoID & "';"

Dim DS_Details As New DataSet
Dim DA4 As New OleDb.OleDbDataAdapter(strSQL, MyConn)

Me.txtColors.Text = DS_Details.Tables(0).Rows(0).Item("Unit_Color")
Me.txtShapes.Text = DS_Details.Tables(0).Rows(0).Item("Unit_Shape")

MyConn.Close()



ADawn
       
0
ADawn
Asked:
ADawn
2 Solutions
 
Joe_GriffithCommented:
Dim DS_Details As New DataSet
Dim DA4 As New OleDb.OleDbDataAdapter(strSQL, MyConn)
DA4.Fill(DS_Details)
0
 
wtconwayCommented:
Not trying to get points here but just a suggestion for you in the future:

'what Joe_Griffith suggested
Dim DS_Details As New DataSet
Dim DA4 As New OleDb.OleDbDataAdapter(strSQL, MyConn)
DA4.Fill(DS_Details)

'and my additions
Dim tbl as DataTable = DS_Details.Tables(0)
Dim row as DataRow = tbl.Rows(0)

txtColors.Text = row("Unit_Color")
txtShapes.Text = row("Unit_Shape")

Just making it easier to access the data. You might also want to wrap all of database communication around a Try...Catch statement to make sure the connection gets closed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now