Dim sql As String = "Select ProductID From OrderDetail Order By ProductID Desc"
Dim command As New SqlCommand(sql, connection)
Dim reader1 As SqlDataReader = command.ExecuteReader()
如何将所有已检索到的productid存储到数组中?如何将sql查询值存储到数组中
Dim sql As String = "Select ProductID From OrderDetail Order By ProductID Desc"
Dim command As New SqlCommand(sql, connection)
Dim reader1 As SqlDataReader = command.ExecuteReader()
如何将所有已检索到的productid存储到数组中?如何将sql查询值存储到数组中
Dim list As New List(Of Integer)
Using reader As SqlDataReader = command .ExecuteReader()
While reader.Read()
list.Add(reader.GetInt32(reader.GetOrdinal("ProductID")))
End While
End Using
'check list.ToArray() now
编辑:但是,而不是返回数组,我会返回一个整数的泛型列表(如果你只想要回产品ID)或ProductClass
对象
Private Function GetProductIDs() As IList(Of Integer)
Dim list As New List(Of Integer)
Dim conStr = "write your connection string here"
Using connection As New SqlConnection(conStr)
Dim sql As String = "Select ProductID From OrderDetail Order By ProductID Desc"
Dim command As New SqlCommand(sql, connection)
Using reader As SqlDataReader = command.ExecuteReader()
While reader.Read()
list.Add(reader.GetInt32(reader.GetOrdinal("ProductID")))
End While
End Using
End Using
Return list
End Function
的名单
编辑2:按照注释, 要检索标签的文字的摆放,你可以做到这一点
Dim str As String
str = String.Join(",", GetProductIDs())
Label1.Text=str;
假设Label1
是THEI您的标签control.The的d String.Join
方法将返回用逗号分隔的ProductId的一串像"1,2,6,7"
SQLdr = SQLCmd.ExecuteReader 'Gets Data
While dr.Read() 'While Data is Present
MsgBox(dr("Column Name")) 'Show data in a Message Box
End While
Loop While SQLdr.NextResult() 'Move to the Next Record
http://www.daniweb.com/software-development/vbnet/code/216920/sql-in-vb.net
如何检索从所有的值列表到label.text? – FredHomme 2012-07-25 15:15:40
'虽然reader.Read() Sum.Text =(读卡器( “产品ID”)) 端,而 循环while reader.NextResult()' – FredHomme 2012-07-25 15:29:37
有一个在循环而 – FredHomme 2012-07-25 15:30:00