找不到可安装的ISAM

本文关键字:ISAM 安装 找不到 | 更新日期: 2023-09-27 18:10:55

我正在尝试使用c#在。net中创建程序,用于上传excel文件,读取excel文件并从excel数据中添加记录excel文件到sql server数据库。在这样做的时候,我得到了一个错误:无法找到可安装的ISAM?

有人能帮我解决这个问题吗?

或者可以提供一些示例代码以不同的方式进行这种赋值?

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();
                    }
                }
            }
        }
    }
}

}

找不到可安装的ISAM

没有64位版本的Jet OLEDB驱动程序,所以如果你在64位操作系统上运行它,你可能需要在你的。net应用程序中瞄准x86而不是Any CPU。

当连接字符串的语法不正确时也会产生此错误。这通常发生在使用多个Extended Properties参数时。下面是一个例子:

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:'My Documents'Book20.xls;Extended Properties=""Excel 12.0;HDR=NO;IMEX=1"""

像这样更改连接字符串

ConnectionString=" Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:'NAVEEN KUMAR'DOTNET'windows'WindowsApplication1'WindowsApplication1'123.xls;Excel 12.0 Xml;HDR=YES"