Click here to Skip to main content
16,015,635 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello developers, plz I would gladly appreciate any help/ideas on the above subject. I'm actually working on a wpf project and I hv a form that contains textboxes, datepicker, and datagrid (textcolumns). So I would like to save user input on the date, textboxes and the datagrid rows at once into my local machine. I can save data on the textboxes and the date but my BIG problem is saving data from the datagrid rows into my local database.

Plz I need your help coz I've bn stumbling on this for some weeks and I need to progress.

Thanks.
Posted

You can create a DataSet that matches the tables in your database.
Then you can bind the different user controls to the columns in the data tables in the dataset.
The datagrid you bind to one whole data table.

For example, one data table, Table1, for the text boxes and date picker and another table for the datagrid, Table2.

Table1 will only contain data row, but Table2 will contain several rows so here you need to loop through the rows and save them one by one in your DB.

C#
DataRow dr1 = Table1.Rows.FirstOrDefault();
if (dr1 != null)
{
  // Insert row in database 
}


foreach (DataRow dr in Table2.Rows)
{
  // Insert row in database 
}


This is a very rudimentary example, but I hope you get the picture.

// George
 
Share this answer
 
Comments
IsoftTech 3-Jul-14 9:12am    
Tnx George, I appreciate your comment. But I still can't get the real picture yet. Am completely new in c# so I think a real working example will go a long way in helping me out of this challenge at the moment.
Below here is my xaml code:

<window x:class="NewDataGridApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:c="clr-namespace:NewDataGridApp" title="MainWindow" height="350" width="525">
<grid>
<grid.rowdefinitions>
<rowdefinition>
<rowdefinition>
<rowdefinition>

<datagrid grid.row="0" x:name="Newdg" autogeneratecolumns="False">
<datagrid.columns>
<datagridtextcolumn header="FileName" width="*">
<datagridtextcolumn header="Prefix" width="*">
<datagridtextcolumn header="Sign" width="*">
<datagridtextcolumn header="Bin" width="*">
<datagridtextcolumn header="FolderPath" width="*">


<Button Grid.Row="1" Content="Button" HorizontalAlignment="Left" Margin="207,59,0,0" VerticalAlignment="Top" Width="75" Height="22" RenderTransformOrigin="0.5,0.5">
</Button>



Kindly help plz.
Thanks
try saving to xml
DataTable dt = new DataTable();
string xmlString = string.Empty;
using (System.IO.TextWriter writer = new System.IO.StringWriter())
{
dt.WriteXml(writer);

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900