C#EXCEL数据导入到ACCESS数据库 C#EXCEL数据导入到ACCESS数据库,该怎么写,最好有例子参考下, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private DataTable XlsToDataTable(String strpath) { string strConn; strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strpath + ";" + "Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(strConn); OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn); DataTable dt = new DataTable(); myCommand.Fill(dt); return dt; } 或private void button1_Click(object sender, EventArgs e) { string str=""; oleDbConnExcel = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Extended properties=Excel 5.0;Data Source=" + Application.StartupPath.Trim() +"\\a.xls"); oleDbConnExcel.Open(); strGetDataFromExcel = "SELECT * FROM [Sheet1$]"; oleDbCmdExcel = new OleDbCommand(strGetDataFromExcel, oleDbConnExcel); oleDbDataReaderExcel = oleDbCmdExcel.ExecuteReader(); if (oleDbDataReaderExcel.HasRows == true) { oleDbConnAccess.Open(); for (; ; ) { if (oleDbDataReaderExcel.Read()) { str= ""; oleDbCmdAccess = new OleDbCommand(str, oleDbConnAccess); oleDbCmdAccess.ExecuteNonQuery(); oleDbCmdAccess.Dispose(); } else break; } oleDbConnAccess.Close(); } oleDbDataReaderExcel.Close(); oleDbCmdExcel.Dispose(); oleDbConnExcel.Close(); } Winform 鼠标移到单元格显示图片,移出图片消失 C#如何对磁盘分区 C#中很郁闷的问题 怎么绑定到gridview上 从数据库中select出来的数据能不能不用DataSet而直接放入DataTable中呀。 求捕获超级链接字符串的正则表达式 怎么删除TABLE中符合一定条件的记录? c#小问题 在一个Console程序中,想实现cls清屏功能,但是从Console类中并没有发现这个功能。 很急的问题(分快送完了,只能给20分了) MDI子窗体 求一本好的有关C#自定义控件书籍
{
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strpath + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);
DataTable dt = new DataTable();
myCommand.Fill(dt);
return dt;
} 或
private void button1_Click(object sender, EventArgs e)
{
string str="";
oleDbConnExcel = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Extended properties=Excel 5.0;Data Source=" + Application.StartupPath.Trim() +"\\a.xls");
oleDbConnExcel.Open();
strGetDataFromExcel = "SELECT * FROM [Sheet1$]";
oleDbCmdExcel = new OleDbCommand(strGetDataFromExcel, oleDbConnExcel);
oleDbDataReaderExcel = oleDbCmdExcel.ExecuteReader();
if (oleDbDataReaderExcel.HasRows == true)
{
oleDbConnAccess.Open();
for (; ; )
{
if (oleDbDataReaderExcel.Read())
{
str= "";
oleDbCmdAccess = new OleDbCommand(str, oleDbConnAccess);
oleDbCmdAccess.ExecuteNonQuery();
oleDbCmdAccess.Dispose();
}
else
break;
}
oleDbConnAccess.Close();
}
oleDbDataReaderExcel.Close();
oleDbCmdExcel.Dispose();
oleDbConnExcel.Close();
}