我正在尝试从sql服务器检索数据并使用vb.net将其存储在arraylist中,但它只接受一个值并退出while语句。我想跳过sql server表的前3列并从第4列开始阅读。
Dim arr10 As New ArrayList
Dim i3 As Integer
i3 = 3
con.ConnectionString = "Data Source='" + System.Net.Dns.GetHostName + "'; Initial Catalog=hrmdb; Integrated Security=True"
con.Open()
Dim q1 As String = "SELECT * from empsal where emplycode='" + s2.ToString + "'"
Dim cm1 = New SqlCommand(q1, con)
Dim dr1 As SqlDataReader = cm1.ExecuteReader()
While dr1.Read()
arr10.Add(dr1(i3).ToString)
i3 = i3 + 1
End While
dr1.Close()
con.Close()
答案 0 :(得分:0)
While dr1.Read()
For i As Integer = 3 to CType(dr1, IDataRecord).FieldCount - 1
arr10.Add(dr1(i).ToString)
Next
End While