Returning Dataset result to silverlight


  • Hi,

    I read lot of articles regarding Returning dataset result to Silverlight to fill Grid control.

    None matched with my requirement.

    Procedure i am following to Bind the Grid: 

    Step 1) I am requesting to WCF to bind grid.

    Step 2) wcf is going to class file called as controller.vb

    Step 3) controller is requesting to BuildQuery class file

    Step 4) BuildQuery.vb file requesting to ExecQuery.vb file.

    Step 5) In this class file (ExecQuery.vb) , query is executing against the DataBase, and result is storing in DATASET.

    As i know, we can't pass DATASET directly from WCF to bind the grid.

    So, i need to perform some manipulations here and the result is passed through WCF to bind my Grid.

    Whats the mechanism i need to follow here.

    REQUIREMENT is no class files should be added in Silverlight application.

    Can any one please help me on this..


    Monday, June 01, 2009 6:12 AM

All replies

  •  I'm wondering why you need that requirement "you can't add class files in your SL Application"...


    Anyways, try serializing your DataSet to xml objects on your WCF service and read each node in your SL application.

    Monday, June 01, 2009 6:35 AM
  • I am following OBjectModel that's why my requirement is like that.

    I am poor in Dataserialization and bind to grid at SL application

    ex: my query is select * from employee

    can you help me please...

    Monday, June 01, 2009 6:42 AM
  •  I've seen you posted also in sladapter his thread:

    I've just tried it out and it's working very well... it's a really nice solution and should solve your problem... Just download his code and replace the objects.You will have some extra code files but if you really can't use them, make an assembly and reference them.
    Monday, June 01, 2009 6:47 AM
  • HI,

    I already gone through  his code. If we observe sladapter solution, he is using class files in silverlight application to convert the wcf result using dynamicdatabuilder class.

    I don't want to perform any action at SL application side.

    For ex. if we observe list directly we can bind the data to grid like Grid.itemsource=e.result;

    I would like to see my application in this manner. (everything should be done at server side[wcf] and result has to pass directly)

    So i can't use sladapter solution(creating class files at SL application side)

    I am looking for alternative solution.

    Thanks once again...  Please help me anyone

    Monday, June 01, 2009 7:11 AM
  •  hello anil litam,

    Are you working with dynamic properties or do you know them already before you query.

    If you do not have dynamic properties, you can create a class on the WCF site that describes your object and include it as DataMembers so your WCF Service will generate the object details for you on the SL part. Fill the object on WCF side and send it over to SL as an ObservableCollection or Generic List.

    Monday, June 01, 2009 7:24 AM
  • yes i am working for dynamic properties. I tried sladapter approach in varient way.

    But nothing works here. whats the best way to return resultset from WCF to silverlight so that grid to bind automatically like


    I tried lot of things resulting casting errors.

    Monday, June 01, 2009 7:44 AM
  • If you're working with dynamic property stuff, you should use sladapter his approach, I don't think I saw any other working approach to achieve this. You will need some extra code files in your Silverlight Application... anyways, I don't see any problem doing that, it exists to use it like that :)

    The ItemSource accepts Collections (ObservableCollection<>, List<>, ...). Just return a collection from your WCF and bind it to your UI object on the completed part of your Asynchronous call.

    Monday, June 01, 2009 7:54 AM
  • I have a dataset in WCF service. Can you please tell me how to convert this DataSet to   ObservableCollection or List to bind my grid.

    Please help me...

    Monday, June 01, 2009 8:47 AM
  •  Hi,

    You can try to refer below code to convert the DataTable into list.

      List<DataRow> list = ds.DataTables[0].AsEnumerable().ToList();
            this.GridView2.DataSource = list;

    Friday, June 05, 2009 4:47 AM
  •  I am not getting datarow in XMAL page and i am using VB.NET

    I am passing my dataset directly to the following function

    Public Shared Function FromDataSet(ByVal ds As DataSet) As DataSetData

            Dim dsd As New DataSetData()
            dsd.Tables = New ObservableCollection(Of DataTableInfo)()
            For Each t As DataTable In ds.Tables
                'Dim tableInfo As New DataTableInfo()

                Dim tableInfo As DataTableInfo = New DataTableInfo()
                tableInfo.TableName = t.TableName
                tableInfo.Columns = New ObservableCollection(Of DataColumnInfo)()
                For Each c As DataColumn In t.Columns
                    'DataColumnInfo col = new DataColumnInfo { ColumnName = c.ColumnName, ColumnTitle = c.ColumnName, DataTypeName = c.DataType.FullName, MaxLength=c.MaxLength, IsKey=c.Unique, IsReadOnly=(c.Unique || c.ReadOnly), IsRequired = !c.AllowDBNull};

                    Dim col As DataColumnInfo = New DataColumnInfo()
                    col.ColumnName = c.ColumnName
                    col.ColumnTitle = c.ColumnName
                    col.DataTypeName = c.DataType.FullName
                    col.MaxLength = c.MaxLength
                    col.IsKey = c.Unique
                    col.IsReadOnly = (c.Unique Or c.ReadOnly)
                    col.IsRequired = Not c.AllowDBNull

                    If c.DataType Is GetType(System.Guid) Then
                        col.IsReadOnly = True
                        col.DisplayIndex = -1
                    End If

            dsd.DataXML = ds.GetXml()
            Return dsd
        End Function

    This result i am sending directly to xaml page through WCF

    From the SL end i am doing following manipulations


    MessageBox.Show(e.Result.DataXML())   -->   it is displaying total output records in the XML format
            For Each mylval In e.Result.Tables()
                For Each col In mylval.Columns
                    Dim TextColumn As New DataGridTextColumn
                    TextColumn.Header = col.ColumnName
                    TextColumn.Binding = New Binding("kumar")
    When i use the above code, columns are binding dynamically but data is not coming
    HOw can i get data for respective column for binding my GRID.
    Saturday, June 06, 2009 1:49 AM
  • Hi there,

    The easiest way to send ADO.Net DataSet to Silvelight application:

    Best regards

    Vitaly Laskarzhevsky

    Wednesday, March 24, 2010 10:45 PM
  •  var employee = new ObservableCollection<Employee>
                        (dsEmp.Tables[0].AsEnumerable().Select(p => new Employee
                            EmpNo = p.Field<int>("EmpNo"),
                            EmpName = p.Field<string>("EmpName"),
                            Sal = p.Field<int>("Sal")

    Monday, October 31, 2011 8:44 AM