用C#.net编写导入导出EXCEL文件的代码。编绎运行后,错误提示: 找不到可安装的ISAM

   用C#.net编写导入导出EXCEL文件的代码。编绎运行后,错误提示: 找不到可安装的ISAM
   解决方案:
   1。修复一下你的OFFICE,确定OFFICE没有问题。
   2。判断你的连接字符串是否有问题。
   3。我自己调试通过的代码:
///导入:
   string MyFileName = @"C://abc.XLS";
            string MyTableName = "Sheet1";
        
            try
            {
                string MyConnectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C://abc.XLS;Extended Properties='Excel 8.0;HDR=NO;IMEX=1'";
                string MySQL = "SELECT * FROM [" + MyTableName + "$]";
               
          
                OleDbConnection myconn = new OleDbConnection(MyConnectionstring);
                myconn.Open();
                OleDbDataAdapter adp = new OleDbDataAdapter(MySQL, myconn);
                adp.Fill(ds, "res");
                myconn.Close();
                MessageBox.Show("Excel文件:" + MyFileName + "创建成功!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dataGridView1.DataSource = ds.Tables["res"];
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message , "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }


///导出:

  DateTime dt=DateTime.Now ;
            string myname ="C://d1d.xls";
            string mytablename = "Sheet1";
            try
            {
                string sql = "编号 char(255),姓名 char(255),种类 char(255),组织 char(255),班组 char(255),职务 char(255),日期 char(255)";
                 sql = " Create Table " + mytablename + "(" + sql + ")";
                string MyConnectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + myname +"';Excel 8.0;HDR=YES";
                OleDbConnection olconn = new OleDbConnection(MyConnectionstring);
                 olconn.Open();
                 OleDbCommand cmd = new OleDbCommand(sql, olconn);
                 cmd.ExecuteNonQuery();
                 for (int i = 1; i < ds.Tables[0].Rows.Count; i++)
                 {
                     string a = ds.Tables[0].Rows[i][0].ToString();
                     string b = ds.Tables[0].Rows[i][1].ToString();
                     string c = ds.Tables[0].Rows[i][2].ToString();
                     string d = ds.Tables[0].Rows[i][3].ToString();
                     string f = ds.Tables[0].Rows[i][4].ToString();
                     string g = ds.Tables[0].Rows[i][5].ToString();
                     sql = "INSERT INTO [" + mytablename + "$]([编号],[姓名],[种类],[组织],[班组],[职务],[日期])VALUES('" + a + "','" + b + "','" + c + "','" + d + "','" + f + "','" + g+ "','" + dt.ToShortDateString() + "')";
                     OleDbCommand cmd1 = new OleDbCommand(sql, olconn);
                     cmd1.ExecuteNonQuery();
              
                 }
                   olconn.Close();
                 MessageBox.Show("Excel文件:" + mytablename + "创建成功!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

4.调试通过。

阅读更多

找不到安装ISAM

05-26

找不到可安装的 ISAMrn我正在做一个学生素质拓展系统,需要生成一些素质拓展方案,但是老是错在这一个Click事件上,希望大家帮帮挑一下错误,这是我的毕业设计来的,谢谢大家rn可能会有两个错误,一个是 找不到可安装的 ISAMrn一个是myArray这个数组这里,rnrn谢谢大家了,有点乱,希望大家帮帮小弟,不然毕不了业了,呵呵 !辛苦,谢谢rnrnrn Sub Sure_Click(ByVal Sender As Object, ByVal E As EventArgs) Handles check.Clickrn rn Dim a As Integerrn Dim st1 As Stringrn Dim j, k As Integerrn Dim Arr1(), T1() As Integerrn Dim da As OleDbDataAdapterrn Dim ds As New DataSetrn Dim myArray() As Int32rn st1 = DropDownList1.SelectedItem.Value '开场类的培训方向 rn a = DropDownList5.SelectedItem.Value '开场类的游戏个数rnrnrn da = New OleDbDataAdapter("SELECT GameNo FROM games WHERE GameClassify = '开场' and GameType='" & st1 & "'","Provider=Microsoft.Jet.OLEDB.4.0;Database=DataBase.mdb;")rn da.Fill(ds)rn ReDim myArray(ds.Tables(0).Rows.Count - 1)rn For i As Int32 = 0 To ds.Tables(0).Rows.Count - 1rn myArray(i) = ds.Tables(0).Rows(i)(0) 将选择出来的GameNo存入myArray数组rn Nextrn ReDim T1(a - 1)rn For j = 0 To a - 1rn T1(j) = Int(Rnd() * ds.Tables(0).Rows.Count) + 1rn Next jrn '产生Y to Z之间的X-n个随机数 rn '存入到C(i)中rn ReDim T1(a - 1)rn ReDim Arr1(a - 1)rn For k = 0 To a - 1rn Arr1(k) = myArray(T1(k)) '将GameNo的数据存入到Arr1中rn Next krn rn '''''数据库连接rn rn Dim StrCnn As Stringrn Dim Cnn As OleDbConnectionrn Dim Cmd As OleDbCommandrn Dim dtcmd As OleDbDataAdapterrn Dim dt As New DataTablern Dim Str1 As Stringrn Str1 = " where GameNo=" & T1(1) & " "rn StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("DataBase.mdb")rn Cnn = New OleDbConnection(StrCnn)rn Cnn.Open()rn Str1 = "select GameName,GameClassify,GameType,GameExp,GameTime from games " & Str1 & " order by GameName desc"rn dtcmd = New OleDbDataAdapter(Str1, Cnn)rn dtcmd.Fill(dt)rn DataGrid1.DataSource = dtrn DataGrid1.DataBind()rn Cnn.Close()rnrn rn End Subrn

没有更多推荐了,返回首页