找不到可安装ISAM [英] Could not find installable ISAM
问题描述
我想创建一个使用C#上传Excel文件,阅读它计划在.net中,并添加记录excel文件从Excel数据的SQL Server数据库。 这样做虽然我已经得到了一个错误:找不到可安装ISAM
I am trying to create program in .net using C# for uploading excel file, reading it and add record excel file to the sql server database from excel data. While doing so I have got an error: Could not find installable ISAM?
有人可以帮助我如何解决这个问题呢?
Can someone help me how to fix this problem?
或者可能会提供一些样品code做了这样一种分配在不同的方式?
Or may be provide some sample code to do such kind of assignment in different way?
protected void Button1_Click(object sender, EventArgs e)
{
String excelConnectionString1;
String fname = FileUpload1.PostedFile.FileName;
if (FileUpload1.PostedFile.FileName.EndsWith(".xls"))
{
String excelsheet;
FileUpload1.SaveAs(Server.MapPath("~/file/" + FileUpload1.FileName));
if (FileUpload1.PostedFile.FileName.EndsWith(".xls"))
{
excelConnectionString1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/file/" + FileUpload1.FileName) + ";Extended Properties=Excel 8.0;HDR=Yes;";
OleDbConnection myEcelConnection1 = new OleDbConnection(excelConnectionString1);
myEcelConnection1.Open();
if (txtsheet.Text.Length == 0)
{
lblmsg.Text = "Please Write File Name";
}
else
{
excelsheet = "[" + txtsheet.Text + "$" + "]";
string sheet = "Select * from [" + txtsheet.Text + "$" + "]";
OleDbCommand cmd1 = new OleDbCommand(sheet, myEcelConnection1);
cmd1.CommandType = CommandType.Text;
OleDbDataAdapter myAdapter1 = new OleDbDataAdapter(cmd1);
DataSet myDataSet1 = new DataSet();
myAdapter1.Fill(myDataSet1);
int a = myDataSet1.Tables[0].Rows.Count - 1;
string name;
string dob;
for (int i = 0; i <= a; i++)
{
name = myDataSet1.Tables[0].Rows[i].ItemArray[0].ToString();
dob = myDataSet1.Tables[0].Rows[i].ItemArray[1].ToString();
SqlConnection con = new SqlConnection("Connection String for Sql Server");
con.Open();
SqlCommand command = new SqlCommand("Insert into info(name,dob)values(@valname,@valdob)", con);
command.Parameters.Add("@valname", SqlDbType.VarChar, 50).Value = name;
command.Parameters.Add("@valdob", SqlDbType.VarChar, 50).Value = dob;
command.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
}
}
}
}
}
}
}
推荐答案
有没有64位版本的Jet OLEDB驱动程序,所以如果你在64位操作系统上运行这一点,你可能需要针对86在你的.NET应用程序而不是任何CPU。
There's no 64 bit version of the Jet OLEDB drivers, so if you are running this on a 64 bit OS you might need to target x86 in your .NET application and not Any CPU.
或
在连接字符串的语法不正确,也会产生这个错误。这通常使用多个扩展属性参数时出现。下面是一个例子:
This error will also be generated when the syntax of the connection string is incorrect. This commonly occurs when using multiple Extended Properties parameters. Below is an example:
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\Book20.xls;Extended Properties=""Excel 12.0;HDR=NO;IMEX=1"""
这样的更改连接字符串
Change connection string like this
ConnectionString=" Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\NAVEEN KUMAR\DOTNET\windows\WindowsApplication1\WindowsApplication1\123.xls;Excel 12.0 Xml;HDR=YES"
这篇关于找不到可安装ISAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!