Solved

Addressing a DataRow by field name instead of

Posted on 2010-08-30
2
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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 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.

751 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