开发者

How to populate arraylist with SQL query?

开发者 https://www.devze.com 2023-03-28 06:24 出处:网络
I am developing a VB.NET ASPX file.This report is currently working but now I want to add a parameter which should be an array list displaying all records from below SQL query:

I am developing a VB.NET ASPX file. This report is currently working but now I want to add a parameter which should be an array list displaying all records from below SQL query:

" select distinct instrument_name AS instrument_name from FRUD.tblXref order by instrument_name "

But this array list displays "System.Data.Common" for all possible values from code:

Sub Main()          
Dim pcSQL As String
Dim ProductList As New ArrayList()

pcSQL = " select distinct instrument_name AS instrument_name from FRUD.tblXref order by instrument_name "
Dim DBConn As SqlConnection
DBConn = New SqlConnection(ConfigurationManager.AppSettings("AMDMetricsConnectionString"))
DBConn.Open()
Dim reader As SqlDataReader
Dim DBCommand As New SqlCommand(pcSQL, DBConn)
reader = DBCommand.ExecuteReader()

dProdCodeSearch.DataSource = reader
dProdCodeSearch.DataBind()
re开发者_开发知识库ader.Close()

I am sure I am doing something wrong which is a really simple fix. This SQL Connection works for my data tables in this report. But this is only parameter that I set to SQL output.


You need to create a Collection that is storing the values from the database and then read those values into an array. Something like

Dim instrumentNames As New List(Of String)

While reader.Read()
   instrumentNames.Add(reader.GetString("insturment_name"))
End While

dProdCodeSearch.DataSource = insturmentNames
0

精彩评论

暂无评论...
验证码 换一张
取 消