You need to sign in to do that
Don't have an account?

Create datatabe / dataset from the results of QueryResult
Hi,
I am using Enterprise WSDL with VB.Net 2.0. I Want to return ADO.NET datatabe / dataset based on the below code:-
Dim qr As QueryResult = Nothing
qr = binding.query("select id, Website, Name from Account")
If qr.size > 0 Then
Dim account As Account = CType(qr.records(0), Account)
Dim Id As String = account.Id
Dim Website As String = account.Website
End If
- So, I would like to return all the rows of account QueryResult as a datatable ? What would be the best way?
- Do you provide any CreateDataTable methods in the webservice ?
Regards,
http://forums.sforce.com/sforce/board/message?board.id=NET_development&message.id=5942#M5942
We started going down this path of trying to convert any SOQL to a dataset with nested datatables, but abandoned the idea early on. I believe you'll get cleaner, more maintainable code if you stick to working with collections of objects. e.g.:
(Apologies if my syntax is slightly off, I haven't worked with the Enterprise WSDL)
Unless you're using a pre-2.0 version of .NET, you'll find that you can bind to such collections of objects just as easily through ObjectDataSources as you would be able to a dataset / datatable.
Dim oDataSet As New DataSet
Dim oResult As New sforce.QueryResult
oResult = oProxy.query("SELECT ID, ContactId, CaseNumber, Subject, Status FROM Case " & sWhere)
If Not oResult.records Is Nothing AndAlso oResult.records.Length > 0 Then
Dim oCase As sforce.Case
Dim oTable As New System.Data.DataTable
' add columns
oTable.Columns.Add("ID")
oTable.Columns.Add("ContactID")
oTable.Columns.Add("CaseNumber")
oTable.Columns.Add("Subject")
oTable.Columns.Add("Status")
oDataSet.Tables.Add(oTable)
' add data
For Each oCase In oResult.records
Dim oDataRow As DataRow = oDataSet.Tables(0).NewRow
oDataRow.Item(0) = oCase.Id
oDataRow.Item(1) = oCase.ContactId
oDataRow.Item(2) = oCase.CaseNumber
oDataRow.Item(3) = oCase.Subject
oDataRow.Item(4) = oCase.Status
oDataSet.Tables(0).Rows.Add(oDataRow)
Next
End If
Return oDataSet