将Excel内容导入数据库(ASP.NET/C#)
2008-05-28 12:45
507 查看
思路:先上传XLS文件,然后用OleDB连接Excel文件,将Excel数据导入Dataset,再将Dataset数据导入数据库。
以下是主调入过程
string filename = string.Empty;
try
catch(Exception ex)
finally
private void ImportXlsToData(string fileName)
//上传Excel文件
private string UpdateXls(System.Web.UI.HtmlControls.HtmlInputFile inputfile)
//将Dataset的内容导入SQL
private bool AddDatasetToSQL(DataSet pds)
{
int ic,ir;
ic = pds.Tables[0].Columns.Count;
if (pds.Tables[0].Columns.Count < 7)
{
throw new Exception("导入Excel格式错误!Excel只有" + ic.ToString() + "列");
}
ir = pds.Tables[0].Rows.Count;
if (pds != null && pds.Tables[0].Rows.Count > 0)
{
for (int i = 0;i < pds.Tables[0].Rows.Count;i++)
{
Save(pds.Tables[0].Rows[i][0].ToString(),pds.Tables[0].Rows[i][1].ToString(),
pds.Tables[0].Rows[i][2].ToString(),pds.Tables[0].Rows[i][3].ToString(),
pds.Tables[0].Rows[i][4].ToString(),pds.Tables[0].Rows[i][5].ToString(),
pds.Tables[0].Rows[i][6].ToString());
}
}
else
{
throw new Exception("导入数据为空!");
}
return true;
}
以下是主调入过程
string filename = string.Empty;
try
catch(Exception ex)
finally
private void ImportXlsToData(string fileName)
//上传Excel文件
private string UpdateXls(System.Web.UI.HtmlControls.HtmlInputFile inputfile)
//将Dataset的内容导入SQL
private bool AddDatasetToSQL(DataSet pds)
{
int ic,ir;
ic = pds.Tables[0].Columns.Count;
if (pds.Tables[0].Columns.Count < 7)
{
throw new Exception("导入Excel格式错误!Excel只有" + ic.ToString() + "列");
}
ir = pds.Tables[0].Rows.Count;
if (pds != null && pds.Tables[0].Rows.Count > 0)
{
for (int i = 0;i < pds.Tables[0].Rows.Count;i++)
{
Save(pds.Tables[0].Rows[i][0].ToString(),pds.Tables[0].Rows[i][1].ToString(),
pds.Tables[0].Rows[i][2].ToString(),pds.Tables[0].Rows[i][3].ToString(),
pds.Tables[0].Rows[i][4].ToString(),pds.Tables[0].Rows[i][5].ToString(),
pds.Tables[0].Rows[i][6].ToString());
}
}
else
{
throw new Exception("导入数据为空!");
}
return true;
}
相关文章推荐
- 将Excel内容导入数据库(ASP.NET/C#)
- 将Excel内容导入数据库(ASP.NET/C#)
- 将Excel内容导入数据库(ASP.NET/C#)
- C# 或Asp.Net 将excel表格导入数据库 ····················
- asp.net导入EXCEL内容文件到数据库
- C# 或Asp.Net 将excel表格导入数据库
- C# 或Asp.Net 将excel表格导入数据库
- [Asp.net]常见数据导入Excel,Excel数据导入数据库解决方案,总有一款适合你!
- ASP.NET Excel 导入数据库
- ASP.NET Excel数据导入数据库
- ASP.NET数据库导入Excel格式化打印--ExcelHandler.cs
- ASP.NET从excel中导入试题到SQL SERVER 2005数据库
- ASP.NET 从Excel文件导入数据到数据库
- asp.net将本地Excel上传到服务器并把数据导入到数据库
- ASP.NET Excel数据导入数据库
- ASP.NET中数据库数据导入Excel、Word并打印
- asp.net 读取 (导入) CSV文件内容 到页面 (数据库)
- ASP.NET 从Excel文件导入数据到数据库(笔记)
- asp.net 实现excel导入到数据库
- ASP.NET excel 导入数据库 出现 未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序问题的解决