用C#导出和导入 [英] Export and import in C#

查看:83
本文介绍了用C#导出和导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将数据从sql导出到excel,其工作正常,导出用户将在excel中做一些更改,应该在sql中更新,方法是通过ID导入excel到sql,在C#中请帮助我



我尝试过的事情:



从sql导出数据,最终表现优异

解决方案

请参阅这些链接,将excel文件上传到DataSet / DataTable。

使用C#读取和导入Excel文件到DataSet或DataTable中ASP.Net中的VB.Net [ ^ ]

将Excel工作表数据读入DataTable [ ^ ]
将$ excel转换为DataTable后,
,迭代DataTable的每一行以获取Id和其他参数以将值更新到数据库中



< pre lang =C#> foreach (DataRow row in dtExcel.Rows)
{
int id;
int .TryParse(row [ Your_ID_Column_Name ]。ToString(), out id);
string column1Data = row [ 第1列名称]的ToString();
string column2Data = row [ 第2列名称]的ToString();

// 使用ADO.Net更新数据库表中的项.... / span>


}


i want to export data from sql to excel intially its works fine, after export users will do some changes in excel that should be update in sql by importing excel to sql by ID , in C# please help me

What I have tried:

export data from sql to excel intially its works fine

解决方案

Refer these links for uploading an excel file to a DataSet/DataTable.
Read and Import Excel File into DataSet or DataTable using C# and VB.Net in ASP.Net[^]
Read Excel Sheet Data into DataTable[^]
after converting the excel to a DataTable, Iterate each rows of the DataTable to get the Id and other parameters to update the values into the Database

foreach (DataRow row in dtExcel.Rows)
            {
                int id;
                int.TryParse(row["Your_ID_Column_Name"].ToString(), out id);
                string column1Data = row["Column 1 Name"].ToString();
                string column2Data = row["Column 2 Name"].ToString();

                // Using ADO.Net update the Item in the Database Table....


            }


这篇关于用C#导出和导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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