Solved

Addressing a DataRow by field name instead of

Posted on 2010-08-30
2
380 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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 …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

786 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