急求高手指点!程序修改之后,点击button按钮,为什么没有反应??

程序运行时并没有报错,但是点击button没有反应,请高手们再帮忙看看 !我用的数据库是Access的 表中一共有四列,编号、课程、成绩、学期!

private void button2_Click(object sender, System.EventArgs e)
        {
            string sql, xq1, xq2;
            xq1 = textBox2.Text.Trim() + numericUpDown1.Value.ToString();
            xq2 = textBox3.Text.Trim() + numericUpDown2.Value.ToString();
            sql = "select ScoreId as 编号,Course as 课程,Score as 成绩,cstr(cint(Semester/10))+'-'+cstr(cint(Semester/10)+1)+'年度第'+cstr(Semester mod 10)+'学期' as 学期 from ScoreInfo where StudentNumber='" + textBox1.Text.Trim() + "' and Semester between '" + xq1 + "'and '" + xq2 + "' order by Semester desc";
            OleDbDataAdapter adp = new OleDbDataAdapter(sql, oleDbConnection1);
            DataSet ds = new DataSet();
            adp.Fill(ds, "score");
            AddExcel(ds);

        }

        protected void AddExcel(DataSet ds)
        {
            DataTable dt = ds.Tables["score"];
            string fileName = Guid.NewGuid() + ".xls";
            Excel.Application excel = new Excel.ApplicationClass();
            int rowIndex = 1;
            int colIndex = 0;
            excel.Application.Workbooks.Add(true);

            foreach (DataColumn col in dt.Columns)
            {
                colIndex++;
                excel.Cells[1, colIndex] = col.ColumnName;
            }
            foreach (DataRow row in dt.Rows)
            {
                rowIndex++;
                colIndex = 0;
                for (colIndex = 0; colIndex < dt.Columns.Count; colIndex++)
                {
                    excel.Cells[rowIndex, colIndex + 1] = row[colIndex].ToString();
                }
            }
            excel.Visible = false;
            excel.ActiveWorkbook.SaveAs(fileName, Excel.XlFileFormat.xlExcel9795, null, null, false, false, Excel.XlSaveAsAccessMode.xlNoChange, null, null, null, null, null);
            excel.Quit();
            excel = null;
            GC.Collect();
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值