WPF and Dataset xsd,xsc,xss?

Asked By Kannabiran .
22-Aug-08 09:03 AM
Earn up to 0 extra points for answering this tough question.

HI,

   Im using wpf for designing purpose,i have to use dataset in my project, but im new to this one.i dont know how to use.i added dataset to my project by soln explorer--> add newitem-->Dataset. but i dont know whats the purpose of this one and i dont know how to use this one.. and also i need to know is it possible to store the values?.. could any one assist me??

regrds

Kanna..

  hi

Binny ch replied to Kannabiran .
22-Aug-08 09:08 AM

 following is the code snippet for adding DataRow into the Dataset.

ExampleRow = myDataTable.NewRow();
ExampleRow["Name"] = "testname";
ExampleRow["Age"] = 25;
myDataTable.Rows.Add(ExampleRow);

Go through these article hope they help you:

http://aspalliance.com/856_Working_with_DataSet_Objects_and_XML

http://msdn.microsoft.com/en-us/library/ss7fbaez.aspx

http://www.codeproject.com/KB/cpp/dataset.aspx

http://www.codersource.net/dataset_dot_net.html

  See this info and code

Sagar P replied to Kannabiran .
22-Aug-08 09:10 AM

which will tell you how to bind dataset with list view with WPF,

This blog entry demonstrates the fundamentals of binding a WPF TreeView to a DataSet with two related DataTables. The technique presented herein could easily be extended to fit more sophisticated requirements, such as binding to more than two tables.

Many applications need to display hierarchical data in a TreeView, and often that data is retrieved from a database. In many situations the developer just needs to bind the TreeView directly to the DataSet which was populated with database data; creating custom domain objects and collections of those objects can be overkill sometimes. If you are currently in that situation, rest assured that it is actually fairly trivial to do this in WPF. :)

The basic gist of the solution is to bind the top level of TreeViewItems against the master DataTable, and then bind against DataRelations for any descendants of the root nodes. You need to use a HierarchicalDataTemplate for every non-leaf level of nodes, in other words, only the very lowest DataTable in the hierarchy is displayed with a non-hierarchical DataTemplate.

Let’s just get right into an example. Here is a method in a class called DataSetCreator which creates a DataSet with two related DataTables:

Creating a hierarchical DataSet

The resultant DataSet has two DataTables (‘Master’ and ‘Detail’) and one DataRelation (‘Master2Detail’). We want a TreeView to display the Master rows as top-level nodes and the Detail rows as children of their respective parent node. Here is the XAML for a Window which contains a TreeView configured to load and display that data:

Binding a TreeView to a DataSet

If you had, say, three related tables (Master –> Detail –> DetailInfo) then you could have the ‘DetailTemplate’ be a HierarchicalDataTemplate whose ItemsSource was bound to the DataRelation between ‘Detail’ and ‘DetailInfo,’ and the ItemTemplate a DataTemplate which displays the pertinent information in that table.

When you run the demo application and expand the root nodes, the TreeView looks like this:

The bound TreeView

Also go thr these links for more details;

http://forums.msdn.microsoft.com/en-US/wpf/threads/

http://rrelyea.spaces.live.com/blog/cns!167AD7A5AB58D5FE!1833.entry

http://www.codeproject.com/KB/miscctrl/GridView_WPF.aspx

Best Luck!!!!!!!!!!!!!!!!!!
Sujit.

  Re : WPF and Dataset xsd,xsc,xss?

Deepak Ghule replied to Kannabiran .
22-Aug-08 09:12 AM

private void Window_Loaded(object sender, RoutedEventArgs e)

{

    BindData();          

}

 

private void BindData()

{

    DataSet dtSet = new DataSet();

    using (connection = new SqlConnection(connectionString))

    {

        command = new SqlCommand(sql, connection);              

        SqlDataAdapter adapter = new SqlDataAdapter();          

        connection.Open();

        adapter.SelectCommand = command;

        adapter.Fill(dtSet, "Customers");

        listBox1.DataContext = dtSet;

     

    }

}

 

 

Refer this link, it expain Data Binding in WPF :

http://www.c-sharpcorner.com/UploadFile/mahesh/WPFDataBinding08012008233147PM/WPFDataBinding.aspx

  thanx
Kannabiran . replied to Sagar P
22-Aug-08 09:13 AM

Hi,

Whether it is possible to store the value as permanent in that dataset and by later it can transferred to database..is it possible?

  Thanx
Kannabiran . replied to Binny ch
22-Aug-08 09:17 AM

Hi Binny,

      Im familiar in the server code dataset, for ex: Dataset ds=new Dataset(); im not asking about this dataset.. im adding through solution explorer dataset.. i want to know about that dataset??

  Thanx
Kannabiran . replied to Deepak Ghule
22-Aug-08 09:23 AM

Hi Deepak,

      DataSet dtSet = new DataSet();

    using (connection = new SqlConnection(connectionString))

    {

        command = new SqlCommand(sql, connection);              

        SqlDataAdapter adapter = new SqlDataAdapter();          

        connection.Open();

        adapter.SelectCommand = command;

        adapter.Fill(dtSet, "Customers");

        listBox1.DataContext = dtSet;

     

    }

 

You are using this codefile Dataset to fill the value..then whats the purpose of that adding from solution explorer dataset?? actually whats the use of that one?and what are the advatages by using that?

  See
Sagar P replied to Kannabiran .
23-Aug-08 03:47 AM

you can store a datset value as a global varialbe so that you can use it in all the form.

Or you can store it in class variable so that you can access it on other forms by creating an objct of that.

And the thing you are asking abt Dataset dragging as design time. I think its something same like you add dataset while coding bu using code;

Dataset ds=new Dataset();

You can use that datset for same purpose as this.

Best Luck!!!!!!!!!!!!!
Sujit.

  Use this
Atul Shinde replied to Kannabiran .
25-Aug-08 12:32 AM

private void Window_Loaded(object sender, RoutedEventArgs e)

{

    BindData();          

}

 

private void BindData()

{

    DataSet dtSet = new DataSet();

    using (connection = new SqlConnection(connectionString))

    {

        command = new SqlCommand(sql, connection);              

        SqlDataAdapter adapter = new SqlDataAdapter();          

        connection.Open();

        adapter.SelectCommand = command;

        adapter.Fill(dtSet, "Customers");

        listBox1.DataContext = dtSet;

     

    }

}

 

 

Refer this link, it expain Data Binding in WPF :

http://www.c-sharpcorner.com/UploadFile/mahesh/WPFDataBinding08012008233147PM/WPFDataBinding.aspx

  Try this...
Atul Shinde replied to Kannabiran .
25-Aug-08 12:32 AM
following is the code snippet for adding DataRow into the Dataset.
ExampleRow = myDataTable.NewRow();
ExampleRow["Name"] = "testname";
ExampleRow["Age"] = 25;
myDataTable.Rows.Add(ExampleRow);

Go through these article hope they help you:

http://aspalliance.com/856_Working_with_DataSet_Objects_and_XML

http://msdn.microsoft.com/en-us/library/ss7fbaez.aspx

http://www.codeproject.com/KB/cpp/dataset.aspx

http://www.codersource.net/dataset_dot_net.html

  WPF
Atul Shinde replied to Kannabiran .
25-Aug-08 12:32 AM

This blog entry demonstrates the fundamentals of binding a WPF TreeView to a DataSet with two related DataTables. The technique presented herein could easily be extended to fit more sophisticated requirements, such as binding to more than two tables.

Many applications need to display hierarchical data in a TreeView, and often that data is retrieved from a database. In many situations the developer just needs to bind the TreeView directly to the DataSet which was populated with database data; creating custom domain objects and collections of those objects can be overkill sometimes. If you are currently in that situation, rest assured that it is actually fairly trivial to do this in WPF. :)

The basic gist of the solution is to bind the top level of TreeViewItems against the master DataTable, and then bind against DataRelations for any descendants of the root nodes. You need to use a HierarchicalDataTemplate for every non-leaf level of nodes, in other words, only the very lowest DataTable in the hierarchy is displayed with a non-hierarchical DataTemplate.

Let’s just get right into an example. Here is a method in a class called DataSetCreator which creates a DataSet with two related DataTables:

Creating a hierarchical DataSet

The resultant DataSet has two DataTables (‘Master’ and ‘Detail’) and one DataRelation (‘Master2Detail’). We want a TreeView to display the Master rows as top-level nodes and the Detail rows as children of their respective parent node. Here is the XAML for a Window which contains a TreeView configured to load and display that data:

Binding a TreeView to a DataSet

If you had, say, three related tables (Master –> Detail –> DetailInfo) then you could have the ‘DetailTemplate’ be a HierarchicalDataTemplate whose ItemsSource was bound to the DataRelation between ‘Detail’ and ‘DetailInfo,’ and the ItemTemplate a DataTemplate which displays the pertinent information in that table.

When you run the demo application and expand the root nodes, the TreeView looks like this:

The bound TreeView

Also go thr these links for more details;

http://forums.msdn.microsoft.com/en-US/wpf/threads/

http://rrelyea.spaces.live.com/blog/cns!167AD7A5AB58D5FE!1833.entry

http://www.codeproject.com/KB/miscctrl/GridView_WPF.aspx

Create New Account