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
       
ADawnAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joe_GriffithCommented:
Dim DS_Details As New DataSet
Dim DA4 As New OleDb.OleDbDataAdapter(strSQL, MyConn)
DA4.Fill(DS_Details)
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.