Solved

Addressing a DataRow by field name instead of

Posted on 2010-08-30
2
362 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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

772 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

11 Experts available now in Live!

Get 1:1 Help Now