Solved

Addressing a DataRow by field name instead of

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Microsoft – Kerberos Configuration Manager. Delegation service account query 1 37
SQL, add where clause 5 23
SQL R 21 23
RAISERROR WITH NOWAIT 2 14
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

790 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