我正在寻找从选定的SQL字符串填充一个数组或一组变量。
我知道SQL字符串会从3个不同的行中给出3个值,但我无法弄清楚如何将每个值分别分配给变量(我会将所有3个变量设置为每个项目)
我知道代码不对,但也许它会让我更好地了解我想要实现的目标:
Dim network_default(3) As String
network_default(0) = "Array item 1"
network_default(1) = "Array item 2"
network_default(2) = "Array item 3"
Using dbConnection As New OleDbConnection(My.Settings.SMSA_databaseConnectionString)
Try
dbConnection.Open()
Catch ex As Exception
MessageBox.Show("Cannot create a connection to the database object")
Application.Exit()
End Try
Dim sqlcommand As String
sqlcommand = "SELECT Services.[Service], Services.[IP], Services.[Description] FROM Services WHERE (((Services.[Default])=True));"
Dim getSomeData As New OleDbCommand(sqlcommand, dbConnection)
With getSomeData
.Parameters.AddWithValue("@variableName", "variableValue")
End With
Using dataReader As OleDbDataReader = getSomeData.ExecuteReader
Do While dataReader.Read
For i As Integer = 0 To 3
network_default(i) = dataReader("IP")
Next
Loop
End Using
dbConnection.Close()
End Using
由于