locked
how to put sql result set into array ? RRS feed

  • 問題

  • Hi,

    I want put the sql result set into array in a window form which connect to sql server 2000,

    how to code it ?

     

    please give some hints.

     

    Thanks

     

    Derek Yim

    2008年11月2日 9:17

解答

  • Below is the code snippet for you to reference:

     

    Code Snippet
            Dim conn As New SqlClient.SqlConnection("<your connection string>")
            Dim da As New SqlClient.SqlDataAdapter("<query>", conn)
            Dim dt As New DataTable
            da.Fill(dt)

     

     

    After you got the data table, you can use the Rows collection to get the data row (each record) and the Item collection in the data row to get the cell values.

    2008年11月2日 12:55

所有回覆

  • You can use SQLDataAdapter to populate data from SQL Server to DataSet/DataTable which is already an array-like structure.

    2008年11月2日 10:37
  • Hi, Raymond,

    can you give some example of coding ?

    or any msdn articles for reference ?

     

    Thanks a lot.

     

    Derek

     

    2008年11月2日 12:49
  • Below is the code snippet for you to reference:

     

    Code Snippet
            Dim conn As New SqlClient.SqlConnection("<your connection string>")
            Dim da As New SqlClient.SqlDataAdapter("<query>", conn)
            Dim dt As New DataTable
            da.Fill(dt)

     

     

    After you got the data table, you can use the Rows collection to get the data row (each record) and the Item collection in the data row to get the cell values.

    2008年11月2日 12:55
  •  Derek Yim wrote:

    Hi,

    I want put the sql result set into array in a window form which connect to sql server 2000,

    how to code it ?

     

    please give some hints.

     

    Thanks

     

    Derek Yim

    What is your meaning of putting the result set into array? You want to get the result to be display into a drop-down-list?

    2008年11月3日 14:14