B
Brad Isaac
Hi,
I am trying to cut down on the sheer length of some of my SQL commands
-- especially in reference to pulling column data.
For example, I have one table that has columns named Option 1, Option
2, Option 3 etc.
I created a for / next statement that runs through the same number of
iterations as there are Option columns
Here is the code I tried getting the data from all of the option
colums - it fails because the "SqlVar" variable doesn't seem to grab
the SQL data correctly. If I change from the SqlVar string to
"Option1" it does pull data, although it just pulls one column
I've highlighted the trouble spot with '{{{{ }}}} to make it easy to
find
For x = 1 To 9
Rower = "Row2"
Dim ST(x) As String
Dim S(x) As System.Data.SqlServerCe.SqlCeCommand
Dim DTR(x) As System.Data.SqlServerCe.SqlCeDataReader
'Dim steps As String
SqlVar = "Option" & x
S(x) = New System.Data.SqlServerCe.SqlCeCommand("select '"
& SqlVar & "' from masterlist where RowNum = '" & Rower & "'", cn)
DTR(x) = S(x).ExecuteReader
While DTR(x).Read
' {{{{The SqlVar below always fails. If I change this to "Option1"
It pulls the data from the first column!}}}}
ST(x) = DTR(x)(SqlVar)
End While
Next
Does anyone here have any recommendations or a workaround?
Many thanks,
Brad
I am trying to cut down on the sheer length of some of my SQL commands
-- especially in reference to pulling column data.
For example, I have one table that has columns named Option 1, Option
2, Option 3 etc.
I created a for / next statement that runs through the same number of
iterations as there are Option columns
Here is the code I tried getting the data from all of the option
colums - it fails because the "SqlVar" variable doesn't seem to grab
the SQL data correctly. If I change from the SqlVar string to
"Option1" it does pull data, although it just pulls one column
I've highlighted the trouble spot with '{{{{ }}}} to make it easy to
find
For x = 1 To 9
Rower = "Row2"
Dim ST(x) As String
Dim S(x) As System.Data.SqlServerCe.SqlCeCommand
Dim DTR(x) As System.Data.SqlServerCe.SqlCeDataReader
'Dim steps As String
SqlVar = "Option" & x
S(x) = New System.Data.SqlServerCe.SqlCeCommand("select '"
& SqlVar & "' from masterlist where RowNum = '" & Rower & "'", cn)
DTR(x) = S(x).ExecuteReader
While DTR(x).Read
' {{{{The SqlVar below always fails. If I change this to "Option1"
It pulls the data from the first column!}}}}
ST(x) = DTR(x)(SqlVar)
End While
Next
Does anyone here have any recommendations or a workaround?
Many thanks,
Brad