That's what a DataSet is!
.NET will create a table corresponding to the data you read in with the
SELECT. It will have as column names the names in the query (or their alias
if you use "AS 'Column Name'".
Thank you John.
I wish it would be so easy and I could serialize Dataset or DataTable
back to client written in Adobe Flex 2.
Datasets are not supported, DataTables are working but with a lot of
problems and 'side effects'. The only way it works fast and reliable
is when I use array of objects, something like this:
<WebMethod(Description:="Returns ArrayList", EnableSession:=True)> _
Public Function GetParticipants_Array(ByVal vTop As String) As
Participant()
Dim connection As SqlConnection = New SqlConnection("Data
Source=XZP650;Initial Catalog=rk;Persist Security Info=True;User
ID=xxxx;Password=xxxxx")
Dim vQuery As String = "SELECT TOP " & vTop & " ParticipantID,
LastName, FirstName, SSNumber, Phone, BirthDate, Eligible FROM
tblParticipants ORDER BY ParticipantID DESC"
Dim adapter As SqlDataAdapter = New SqlDataAdapter(vQuery,
connection)
Dim arrList As New ArrayList
Dim custDS As DataSet = New DataSet()
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
adapter.Fill(custDS, "myData")
For Each Row As DataRow In custDS.Tables("myData").Rows
Dim myParticipant As New Participant
With myParticipant
.ParticipantID = Row("ParticipantID")
.LastName = Row("LastName").ToString
.FirstName = Row("FirstName").ToString
.BirthDate = Row("BirthDate").ToString
.SSNumber = Row("SSNumber").ToString
.Phone = Row("Phone").ToString
.Eligible = Row("Eligible")
End With
arrList.Add(myParticipant)
Next
Dim arrParticipant As Participant() =
arrList.ToArray(GetType(Participant))
Return arrParticipant
End Function
Public Class Participant
Public ParticipantID As Int64
Public LastName As String
Public FirstName As String
Public SSNumber As String
Public Phone As String
Public BirthDate As Date
Public Eligible As Boolean
End Class
Flex is able to deserialize this to ArrayCollection and data could be
bound to grids, lists, etc. Would be nice if I could create
Participant class at runtime based on column structure of a DataTable.