如何将Exce中与Sql中的某张表对应字段的数据添加到该表中 如标题 请高手帮忙 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用OLEDB方式读取Excel文件,可以读取为DataTablepublic static DataTable ExcelToDataTable(string strExcelFileName, string strSheetName){ string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strExcelFileName + ";" +"Extended Properties=Excel 5.0;"; string strExcel = string.Format("select * from [{0}$]", strSheetName); DataSet ds = new DataSet(); using (OleDbConnection conn = new OleDbConnection(strConn)) { conn.Open(); OleDbDataAdapter adapter = new OleDbDataAdapter(strExcel, strConn); adapter.Fill(ds, strSheetName); conn.Close(); } return ds.Tables[strSheetName];}再通过查询SQL服务器,得到SQL中的DataTable把Excel中读取出来的数据库添加到那个DataTable中,再提交到数据库就行了添加的时候可以直接循环Excel中的行,再循环SQL中的列设置数据就行了 直接在企业管理器里面点表右键 -> 所以任务 -> 导入数据 -> 数据源选择excel 然后按步骤操作就是了 置顶 http://www.17173pc.com 如何精简我的代码? 初学者关于参数传递 .vshost.exe的一个问题 100分求助!!!!!我的网站在本地能运行,传到空间里面就不能运行了,www.wosaibiz.com 請教ado.net問題 图片上传 怎样判断c:\1.txt是否存在? 很有挑战的问题,如何把2G的文件从客户端保存到SQLServe2000中,要求有进度显示。 [WPF游戏分享]益智游戏--华容道 在C#中如何知道字符串str1中有字符串str2? can't play embedded youtube swf on some computer 关于主从表的getchildrows属性
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strExcelFileName + ";" +"Extended Properties=Excel 5.0;";
string strExcel = string.Format("select * from [{0}$]", strSheetName);
DataSet ds = new DataSet(); using (OleDbConnection conn = new OleDbConnection(strConn))
{
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(strExcel, strConn);
adapter.Fill(ds, strSheetName);
conn.Close();
} return ds.Tables[strSheetName];
}再通过查询SQL服务器,得到SQL中的DataTable把Excel中读取出来的数据库添加到那个DataTable中,再提交到数据库就行了添加的时候可以直接循环Excel中的行,再循环SQL中的列设置数据就行了
http://www.17173pc.com