求各位牛人帮忙改改!!!一直报不支持“Provider ”,这是怎么回事???
//导入按钮
private void button1_Click(object sender, EventArgs e)
{
//获取文件路径
string filePath = this.textBox1.Text.Trim();
if (filePath != "")
{
if (filePath.Contains("xls"))//判断文件是否存在
{
InputExcel(filePath);
}
else
{
MessageBox.Show("请检查您选择的文件是否为Excel文件!谢谢!");
}
}
else
{
MessageBox.Show("请先选择导入文件后,再执行导入!谢谢!");
}
}
private void InputExcel(string pPath)
{
string conn = "Provider = Microsoft.Jet.OLEDB.12.0 ; Data Source =" + pPath + ";Extended Properties='Excel 12.0;HDR=False;IMEX=1'";
SqlConnection oleCon = new SqlConnection(conn);
oleCon.Open();
string Sql = "select * from [retrial]";
SqlDataAdapter mycommand = new SqlDataAdapter(Sql, oleCon);
DataSet ds = new DataSet();
mycommand.Fill(ds, "[retrial]");
oleCon.Close();
int count = ds.Tables["[retrial]"].Rows.Count;
for (int i = 0; i < count; i++)
{
string tRefNum, tReTriState, tReTriStage, tReTriTime, tReTriData, tReTriPayData, tReTriPay, tReTriPayDec, tGetReTriData, tSendReTriData;
tRefNum = ds.Tables["retrial]"].Rows[i]["RefNum"].ToString().Trim();
tReTriState = ds.Tables["[retrial]"].Rows[i]["ReTriState"].ToString().Trim();
tReTriStage = ds.Tables["[retrial]"].Rows[i]["ReTriStage"].ToString().Trim();
tReTriTime = ds.Tables["[retrial]"].Rows[i]["ReTriTime"].ToString().Trim();
tReTriData = ds.Tables["[retrial]"].Rows[i]["ReTriData"].ToString().Trim();
tReTriPayData = ds.Tables["[retrial]"].Rows[i]["ReTriPayData"].ToString().Trim();
tReTriPay = ds.Tables["[retrial]"].Rows[i]["ReTriPay"].ToString().Trim();
tReTriPayDec = ds.Tables["[retrial]"].Rows[i]["ReTriPayDec"].ToString().Trim();
tGetReTriData = ds.Tables["[retrial]"].Rows[i]["GetReTriData"].ToString().Trim();
tSendReTriData = ds.Tables["[retrial]"].Rows[i]["SendReTriData"].ToString().Trim();
string excelsql = "insert into retrial(RefNumReTriStateReTriStageReTriTimeReTriDataReTriPayDataReTriPayReTriPayDecGetReTriDataSendReTriData) "+
"values ('" + tRefNum + "','" + tReTriState + "','" + tReTriStage + "','" + tReTriTime + "','" + tReTriData + "','" + tReTriPayData + "','" + tReTriPay +
"','" + tReTriPayDec + "','" + tGetReTriData + "','" + tSendReTriData + "')";
try
{
//导入到SQL Server中
//DM dm = new DM();
//dm.execsql(excelsql);
MessageBox.Show("数据导入成功!");
}
catch(Exception)
{
MessageBox.Show("数据导入失败!");
}
}
}
[解决办法]
改为这个试试
Provider=Microsoft.ACE.OLEDB.12.0;
[解决办法]
用这个试试看
string conn = "Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source="+ pPath +";"+"Extended Properties=Excel 8.0;";
[解决办法]
SqlConnection oleCon = new SqlConnection(conn);
--->
OleDbConnection
[解决办法]
OledbConnection
[解决办法]
oledbconnectioin
http://msdn.microsoft.com/zh-cn/library/system.data.oledb.oledbconnection(v=vs.80).aspx
[解决办法]
另外,导入数据库最简单的办法是用mssql的导入导出工具Import and Export Data (32-bit)