locked
Binding SqlCeResultSet as Itemsource to DataGrid. RRS feed

  • Question

  • Hello,

     

    I'm using a sqlceresultset to populate a datagrid. After I retrieved and set the ResultSetView property. The DataGrid display the correct column header, and expanded the correct number of rows. But the data rows are all blanks.

    Why is it so ?

     

    Code Snippet

     MyModel>>>>>>>>>>>>>>>>>>>>>>

    public class Model
        {
            SqlCeConnection conn = null;
            SqlCeCommand cmd = null;
            SqlCeResultSet rs = null;
            ResultSetView rsview = null;

            public SqlCeResultSet GetData()
            {
                this.conn = new SqlCeConnection("Data Source = ../../Data/AdventureWorksExt4.0.sdf");
                this.conn.Open();
                this.cmd = conn.CreateCommand();
                this.cmd.CommandText = "Person_Address";
                this.cmd.CommandType = CommandType.TableDirect;
                if (null != rs)
                    rs.Close();
                rs = cmd.ExecuteResultSet(ResultSetOptions.Sensitive | ResultSetOptions.Updatable | ResultSetOptions.Scrollable);
                return rs;
            }

    }

    >>>>>>>>>>>>>

    Code behind>>>>>>>>>

    this.datagrid.ItemsSource = new Model().GetData();

    >>>>>>>>>>>>>>>>>>>>>>>>>>>

    Thanks in advance....


    sankar

    Friday, May 11, 2012 6:09 PM

Answers

  • hi,

    there may be issue with binding Datagrid with SqlceResultSet. Other Possible Solutions are

    1. Using Dataset. Here is the Code sample

    public DataSet GetData()
            {
                this.conn = new SqlCeConnection("Data Source = ../../Data/AdventureWorksExt4.0.sdf");
                this.conn.Open();
     	    SqlCeDataAdapter da = new SqlCeDataAdapter("Select * from Person_Address", this.conn);
    	    DataSet ds = new DataSet();
                da.Fill(_Bind, "MyDataBinding");      
                this.conn.Close();
                return ds;
            }
    2. Using Entity Framework and LINQ

    here is link
    http://erikej.blogspot.in/2011/02/using-sql-server-compact-40-with-wpf.html

    3. If u wish to maintain the SqlceResultSet ,
    u need to convert the ResultSet to ObservableCollection  and assign it to ItemsSource

    regards
    Jagan

    • Edited by Jagan Krishnan Saturday, May 12, 2012 5:12 PM
    • Marked as answer by Kee Poppy Friday, May 18, 2012 7:50 AM
    Saturday, May 12, 2012 5:10 PM

All replies

  • hi,

    here is the discussion thread about the same issues

    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/55f79be9-a170-494b-b3cc-9544dd89d249

    regards

    Jagan

    Saturday, May 12, 2012 11:13 AM
  • Hi Jagan,

    I have already seen that. Since i didnt get the correct solution from there. so i have posted another thread here...

    Thanks for your reply,

    Sankar


    sankar

    Saturday, May 12, 2012 2:14 PM
  • hi,

    there may be issue with binding Datagrid with SqlceResultSet. Other Possible Solutions are

    1. Using Dataset. Here is the Code sample

    public DataSet GetData()
            {
                this.conn = new SqlCeConnection("Data Source = ../../Data/AdventureWorksExt4.0.sdf");
                this.conn.Open();
     	    SqlCeDataAdapter da = new SqlCeDataAdapter("Select * from Person_Address", this.conn);
    	    DataSet ds = new DataSet();
                da.Fill(_Bind, "MyDataBinding");      
                this.conn.Close();
                return ds;
            }
    2. Using Entity Framework and LINQ

    here is link
    http://erikej.blogspot.in/2011/02/using-sql-server-compact-40-with-wpf.html

    3. If u wish to maintain the SqlceResultSet ,
    u need to convert the ResultSet to ObservableCollection  and assign it to ItemsSource

    regards
    Jagan

    • Edited by Jagan Krishnan Saturday, May 12, 2012 5:12 PM
    • Marked as answer by Kee Poppy Friday, May 18, 2012 7:50 AM
    Saturday, May 12, 2012 5:10 PM