使用C#从datagrid保存到sql [英] Saving from datagrid to sql using C#

查看:78
本文介绍了使用C#从datagrid保存到sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Windows应用程序.我已经从Excel文件中检索数据,并将其显示在工作正常的数据网格中.我的问题是将结果从datagrid保存到sql数据库.有人可以帮忙一些C#代码:rolleyes:

I am developing a windows application. I have retrieve data from an excel file and display it in a data grid which is working fine. My problem is saving the results from the datagrid to an sql database. Can someone help with some C# code :rolleyes:

推荐答案

当您仅将数据加载到DataGridView时,
检查Db中是否已存在数据
如果Db中不存在Data,
遍历DataTable.Rows.Count或Dataset.Tables ["].Rows.Count
并运行插入语句.
When u are Loading Data into DataGridView only,
Check already Data Exists in Db or not
if Datanot Exist in Db,
Loop Through the DataTable.Rows.Count or Dataset.Tables[""].Rows.Count
and Run the Insert Statement.


好,
您能提供您的exel文件format.so,以便我对其进行研究吗?
ok,
can u provide your exel file format.so that i can study it


foreach(gridview1.rows中的gridrow对象)
{
//这里获取用于显示excel文件数据的控件的ID
//现在将这些数据保存在以任意字符分隔的字符串中
//like
label lbl =(label)findcontrol("id");
字符串str = lbl.text +"\";
}
//现在使用分割字符串值将数据插入数据库
字符串[] str1 = str.split(''\'');
//现在执行插入查询
foreach(str1中的字符串s)
{
插入命令
}
foreach(gridrow object in gridview1.rows)
{
//here get the id of control which you use to show data of excel file
//now save this data in string splited by any character
//like
label lbl = (label)findcontrol("id");
string str= lbl.text+"\";
}
//now insert data into database using split the string value
string [] str1=str.split(''\'');
//now execute insert query
foreach(string s in str1)
{
insert command
}


这篇关于使用C#从datagrid保存到sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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