Solved

Addressing a DataRow by field name instead of

Posted on 2010-08-30
2
374 Views
Last Modified: 2012-06-22

I'm using the following code, which seems to work fine, but is there a way to address a datarow column/field by its name, instead of by its column index value?

    Private Sub frmPermitEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        StatusBarNavInfo = "Displaying 1 of " & RecordCount & " permits found"
        StatusBar.Items(0).Text = StatusBarNavInfo

        SQLConn = New SqlConnection(SQLConnString)
        SQLConn.Open()
        SQLAdapter = New SqlDataAdapter(strSQL, SQLConn)
        dTable = New DataTable
        SQLAdapter.Fill(dTable)

        DR = dTable.Rows(0)
        Me.txtPermitNo.Text = DR.Item(0)
    End Sub

Open in new window


I guess I could map some contant integers against the fiield name like:

Public Const PermitNo As Integer = 0

but is there another  easier/direct way?
0
Comment
Question by:DRRobinson
2 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 33564613
You can use regular string-names (columnname)

Me.txtPermitNo.Text = DR.Item("YourField")

http://msdn.microsoft.com/en-us/library/146h6tk5.aspx
0
 

Author Closing Comment

by:DRRobinson
ID: 33564697
Hmmm.. I thought that I tried that and it didn't work.. maybe I messad up the syntax when trying.  Thanks for the quick response.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now