Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Howto: Fill some textboxes using a dataset

Posted on 2006-03-27
2
Medium Priority
?
204 Views
Last Modified: 2010-04-23
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
Comment
Question by:ADawn
2 Comments
 
LVL 7

Assisted Solution

by:Joe_Griffith
Joe_Griffith earned 100 total points
ID: 16302859
Dim DS_Details As New DataSet
Dim DA4 As New OleDb.OleDbDataAdapter(strSQL, MyConn)
DA4.Fill(DS_Details)
0
 
LVL 7

Accepted Solution

by:
wtconway earned 100 total points
ID: 16305734
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question