开发者

How to convert a dataset to a format silverlight supports?

I need to display a dataset in a silverlight grid, but I can't figure out the code. Using a dataset at the WCF side is a must. I tried a lot to convert ds to queryable and what not, but it doesn't work, the silverlight gird will not accept it. I also tried sending ds.toxml, but that displays a column of characters on the silverlight datagrid. What should I do?

xaml.cs

 client.GDatasetAsync();


        }

        void client_GDatase开发者_JAVA技巧tCompleted(object sender, ServiceReference1.GDatasetCompletedEventArgs e)
        {


            dataGrid2.ItemsSource =  e.Result[0];
            dataGrid2.DataContext = e.Result[1];
        }

svc.cs wcf service

 [OperationContract]
        public string[] GDataset()
        {
 DataSet ds = new DataSet();


          //  BusinessApplication2.Web.AdventureWorksLTEntities get_conn = new AdventureWorksLTEntities();

            //this also has begin transaction
          //  string connection = get_conn.Connection.ConnectionString;


            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = @"Data Source=A-63A9D4D7E7834\THIRD;Initial Catalog=AdventureWorksLT;Integrated Security=True";

            conn.Open();

            SqlCommand command = new SqlCommand();

            command.CommandText = "SELECT * FROM [AdventureWorksLT].[SalesLT].[Customer]";

            command.CommandType = CommandType.Text;

            command.Connection = conn;

           SqlDataAdapter slqadaptor = new SqlDataAdapter(command.CommandText, command.Connection);

           slqadaptor.Fill(ds, "[AdventureWorksLT].[SalesLT].[Customer]");

            //var wer = ds as List();

            //SqlDataReader reader = command.ExecuteReader().AsQueryable();

            //command. also has begin and end execution

           // IQueryable alpha = command.ExecuteReader().AsQueryable();
           string[] add = new string[2];
           add[0] = ds.GetXml();
           add[1] = ds.GetXmlSchema();
           return add;





        }

result

everything diplayed in one column one character at a time


This is a pain point.

Datasets are not supported in Silverlight so your only option if you have to work with them (as many do if they are returned from existing stored procedures for example) is to dynamically recreate columns to be consumed by the datagrid using reflection.

Fortunately there is a solution out there: http://silverlightdataset.net/silverlightdataset/Default.aspx.

I have not tried it but there is comprehensive documentation and source code with a generous license. One thing to note though I am not sure if this has been updated for silverlight 4, having said that I cannot think why it should not work. As always this would would need testing for your scenario.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜