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
Solved

Find a table column based on column name in ADO .NET

Posted on 2007-03-24
1
210 Views
Last Modified: 2010-04-23
Hi,
I am in need of help trying to convert some old DAO code to ADO.NET
I need to find records in a table to identify and set some other variable for later use. Basically I need to find measurement units. Here is my old VB6 code:

query = "SELECT DISTINCTROW ScanOrder, NetDaqOrder, NetDaq, Channel, "
query = query & "NameLong, NameShort, LowRange, HighRange, "
query = query & "SensorID , InputUnits, Unit, SignalType, CalibrationGroup, "
query = query & "LowMeas, LowReal, MedMeas, MedReal, HighMeas, HighReal, OrderNum "
query = query & "From AIN_Definition "
query = query & "ORDER BY OrderNum;"

Dim query, stuff As Recordset
Set stuff = MyDb.OpenRecordset(query)

Do Until stuff.EOF
      Select Case stuff.Fields("Unit")
              Case "°C", "°F"
                      localtype% = PhysTempe%
                Case "kPa"
                          localtype% = PhysPrAbs2%
                Case "in-lbs"
                          localtype% = PhysTorqu%
      End Select
Loop

My new code uses the same query and I have made the connection, created a dataset and a datatable. Here is my VB.NET code so far:

Dim daAinDefInit As New OleDb.OleDbDataAdapter(query, conn)
Dim dtAinDefInit As New DataTable
Dim drAinDefInit As DataRow
Dim dsAinDefInit As New DataSet("dsAinDefInit")
daAinDefInit.Fill(dtAinDefInit)

My question is: How do I loop through the dataset or dataTable searching the "Unit" column like I did in VB6 above? By the way, the Unit column is not always in the same position in the table for each project so I don't know if it will be in column 1 or 20 or somewhere in between. So I need to be able to find the column based on the string "Unit"

Appreciate any help to point me in the right direction.

Thanks,
Charlie
0
Comment
Question by:charlieb01
1 Comment
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 18787716
dtAinDefInit.Columns("Unit")

Roger
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - TypeInitializer Error 25 32
Call an IPL program from vb.net and pass in a file location parmeter 2 27
VB.NET 1 28
HTML - Color not displaying correctly in EMAIL. 6 49
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

860 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