charlieb01
asked on
Find a table column based on column name in ADO .NET
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(que ry, conn)
Dim dtAinDefInit As New DataTable
Dim drAinDefInit As DataRow
Dim dsAinDefInit As New DataSet("dsAinDefInit")
daAinDefInit.Fill(dtAinDef Init)
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
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(que
Dim dtAinDefInit As New DataTable
Dim drAinDefInit As DataRow
Dim dsAinDefInit As New DataSet("dsAinDefInit")
daAinDefInit.Fill(dtAinDef
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.