如何将所有用户输入数据保存到本地计算机中 [英] How do I save all user input data into my local machine

查看:85
本文介绍了如何将所有用户输入数据保存到本地计算机中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好开发人员,PLZ我很乐意感谢您对上述主题的任何帮助/想法。我实际上正在研究一个wpf项目,我有一个包含文本框,datepicker和datagrid(textcolumns)的表单。所以我想将日期,文本框和数据网格行的用户输入一次保存到本地计算机中。我可以保存文本框和日期的数据,但我的BIG问题是将数据网格行中的数据保存到我的本地数据库中。



Plz我需要你的帮助因为我'我已经磕磕绊绊几周了,我需要进步。



谢谢。

解决方案

你可以创建一个 DataSet 匹配数据库中的表。

然后,您可以将不同的用户控件绑定到数据集中数据表中的列。

绑定的数据网格一个完整的数据表。



例如,一个数据表 Table1 ,用于文本框和日期数据网格的选择器和另一个表,表2



表1 只包含数据行,但 Table2 将包含多行,所以在这里你需要循环遍历行并将它们一个一个地保存在数据库中。



 DataRow dr1 = Table1.Rows.FirstOrDefault(); 
if (dr1!= null
{
// 在数据库中插入行
}


< span class =code-keyword> foreach (DataRow dr in Table2.Rows)
{
// 在数据库中插入行
}





这是一个非常基本的例子,但我希望你能得到这样的结论。



//乔治


< blockquote>尝试保存到xml

DataTable dt = new DataTable();

string xmlString = string.Empty;

using(System.IO .TextWriter writer = new System.IO.StringWriter())

{

dt.WriteXml(writer);



}


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.

解决方案

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.

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


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

}


这篇关于如何将所有用户输入数据保存到本地计算机中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆