kidness123 2016-08-19 11:54 采纳率: 0%
浏览 1028
已结题

c#关于单项查询的问题

private void Command1_Click()
{
int i = 0;
int j = 0;
int k = 0;
Excel.Application xlApp = default(Excel.Application);
Excel.Workbook xlBook = default(Excel.Workbook);
Excel.Worksheet xlSheet = default(Excel.Worksheet);

{

    {

        {

            xlSheet.Columns.AutoFit;
            this.MousePointer = 11;
            for (k = 0; k <= DataGrid1.Columns.Count - 1; k++) //DataGrid所有的列数
            {
                xlSheet.Cells(1, k + 1) = DataGrid1.Columns(k).Caption; //第一行为DataGrid的列标题
            }
            DataGrid1.Scroll (0, - DataGrid1.FirstRow); //导出前拉动过垂直滚动条,这个非常重要
            DataGrid1.Row = 0;
            for (i = 0; i <= DataGrid1.ApproxCount - 1; i++) //DataGrid的所有行数
            {

                for (j = 0; j <= DataGrid1.Columns.Count - 1; j++) //DataGrid所有的列数,若将此数改小到不拉DataGrid的垂直滚动条的时候能看见的行数的时候正常
                {
                    DataGrid1.Col = j;
                    xlSheet.Cells(i + 2, j + 1) = Adodc1.Recordset(j); //DataGrid1.Text '从第二行显示'DataGrid的内容
                }
                if (i < DataGrid1.ApproxCount - 1)
                {
                    DataGrid1.Row = DataGrid1.Row + 1;
                }
            }
            this.MousePointer = 0;
            MsgBox ("导出成功!");
            xlApp.Visible = true;
            //Excel 处于当前窗体
            {

                {

                    {
                    }

                    private void DataGrid1_Click()
                    {

                    }

                    private void Form_Load()
                    {
                        int i = 0;
                        //装入一级类目
                        Combospecialty.AddItem ("全部");
                        this.Load_by_Upper(0);
                        i = 0;
                        while (Arr_ClassName(i) != "")
                        {
                            Combospecialty.AddItem (Arr_ClassName(i));
                            i++;
                        }
                        Combospecialty.ListIndex = 0;
                        //不显示二级类目
                        Comboclass.Visible = false;
                        Combofour.ListIndex = 0;

                    }
                    private void Refresh_culture()
                    {
                        string TmpSource = "";
                        TmpSource = "SELECT S.Student_Id as 学生序号,S.Student_Name as 姓名,S.BadgeID as 学号, " 
                            + " C1.Class_Name as 专业名称,C2.class_name as 班级名称,convert(char,F.Student_Grade) as 学年,F.yearinput as 年度," 
                            + "F.Cet_Four as 四级成绩,   F.Cet_Six as 六级成绩, F.NationPC_Two as 全国计算机二级成绩, " 
                            + "F.NationPC_Three as 全国计算机三级成绩, F.NationPC_Four as 全国计算机四级成绩, F.JsPC_Two as 江苏计算机二级成绩," 
                            + "F.JsPC_Three as 江苏计算机三级成绩,F.Basicjudge_Type as 基本素质测评类型,F.Basicjudge_Score as 基本素质测评分,F.grow_score as 发展素质分," 
                            + "F.Culture_Memo as 文化备注 " 
                            + "FROM Students  S,Classes   C1,classes  C2 ,Student_four  F" 
                            + " WHERE S.Class_Id = C2.Class_Id And S.student_ID=f.student_ID and  C2.UpperId =C1.class_ID And S.Student_Id = F.Student_Id ";
                        if (Combospecialty.ListIndex != 0)
                        {
                            if (Comboclass.ListIndex == 0)
                            {
                                TmpSource = TmpSource + " and C1.class_name=\'" + Strings.Trim(System.Convert.ToString(Combospecialty.Text)) + "\'";
                            }
                            else
                            {
                                TmpSource = TmpSource + " and C1.class_name=\'" + Strings.Trim(System.Convert.ToString(Combospecialty.Text)) 
                                    + "\' and C2.class_name=\'" + Strings.Trim(System.Convert.ToString(Comboclass.Text)) + "\'";
                            }
                        }

                        TmpSource = TmpSource + " and  cast(F.Student_Grade as char)=\'" + Strings.Trim(System.Convert.ToString(Combofour.Text)) + "\'";
                        TmpSource = TmpSource + " order by s.student_ID asc";
                        Adodc1.RecordSource = TmpSource;
                        Adodc1.Refresh;
                        DataGrid1.Refresh;

                        if (Adodc1.Recordset.EOF == true)
                        {
                            //MsgBox "没有数据可供导出!"
                            Command1.Enabled = false;
                        }
                        else
                        {
                            Command1.Enabled = true;
                        }


                    }
        private void Command1_Click()

{
int i = 0;
int j = 0;
int k = 0;
Excel.Application xlApp = default(Excel.Application);
Excel.Workbook xlBook = default(Excel.Workbook);
Excel.Worksheet xlSheet = default(Excel.Worksheet);

{

    {

        {

            xlSheet.Columns.AutoFit;
            this.MousePointer = 11;
            for (k = 0; k <= DataGrid1.Columns.Count - 1; k++) //DataGrid所有的列数
            {
                xlSheet.Cells(1, k + 1) = DataGrid1.Columns(k).Caption; //第一行为DataGrid的列标题
            }
            DataGrid1.Scroll (0, - DataGrid1.FirstRow); //导出前拉动过垂直滚动条,这个非常重要
            DataGrid1.Row = 0;
            for (i = 0; i <= DataGrid1.ApproxCount - 1; i++) //DataGrid的所有行数
            {

                for (j = 0; j <= DataGrid1.Columns.Count - 1; j++) //DataGrid所有的列数,若将此数改小到不拉DataGrid的垂直滚动条的时候能看见的行数的时候正常
                {
                    DataGrid1.Col = j;
                    xlSheet.Cells(i + 2, j + 1) = Adodc1.Recordset(j); //DataGrid1.Text '从第二行显示'DataGrid的内容
                }
                if (i < DataGrid1.ApproxCount - 1)
                {
                    DataGrid1.Row = DataGrid1.Row + 1;
                }
            }
            this.MousePointer = 0;
            MsgBox ("导出成功!");
            xlApp.Visible = true;
            //Excel 处于当前窗体
            {

                {

                    {
                    }

                    private void DataGrid1_Click()
                    {

                    }

                    private void Form_Load()
                    {
                        int i = 0;
                        //装入一级类目
                        Combospecialty.AddItem ("全部");
                        this.Load_by_Upper(0);
                        i = 0;
                        while (Arr_ClassName(i) != "")
                        {
                            Combospecialty.AddItem (Arr_ClassName(i));
                            i++;
                        }
                        Combospecialty.ListIndex = 0;
                        //不显示二级类目
                        Comboclass.Visible = false;
                        Combofour.ListIndex = 0;

                    }
                    private void Refresh_culture()
                    {
                        string TmpSource = "";
                        TmpSource = "SELECT S.Student_Id as 学生序号,S.Student_Name as 姓名,S.BadgeID as 学号, " 
                            + " C1.Class_Name as 专业名称,C2.class_name as 班级名称,convert(char,F.Student_Grade) as 学年,F.yearinput as 年度," 
                            + "F.Cet_Four as 四级成绩,   F.Cet_Six as 六级成绩, F.NationPC_Two as 全国计算机二级成绩, " 
                            + "F.NationPC_Three as 全国计算机三级成绩, F.NationPC_Four as 全国计算机四级成绩, F.JsPC_Two as 江苏计算机二级成绩," 
                            + "F.JsPC_Three as 江苏计算机三级成绩,F.Basicjudge_Type as 基本素质测评类型,F.Basicjudge_Score as 基本素质测评分,F.grow_score as 发展素质分," 
                            + "F.Culture_Memo as 文化备注 " 
                            + "FROM Students  S,Classes   C1,classes  C2 ,Student_four  F" 
                            + " WHERE S.Class_Id = C2.Class_Id And S.student_ID=f.student_ID and  C2.UpperId =C1.class_ID And S.Student_Id = F.Student_Id ";
                        if (Combospecialty.ListIndex != 0)
                        {
                            if (Comboclass.ListIndex == 0)
                            {
                                TmpSource = TmpSource + " and C1.class_name=\'" + Strings.Trim(System.Convert.ToString(Combospecialty.Text)) + "\'";
                            }
                            else
                            {
                                TmpSource = TmpSource + " and C1.class_name=\'" + Strings.Trim(System.Convert.ToString(Combospecialty.Text)) 
                                    + "\' and C2.class_name=\'" + Strings.Trim(System.Convert.ToString(Comboclass.Text)) + "\'";
                            }
                        }

                        TmpSource = TmpSource + " and  cast(F.Student_Grade as char)=\'" + Strings.Trim(System.Convert.ToString(Combofour.Text)) + "\'";
                        TmpSource = TmpSource + " order by s.student_ID asc";
                        Adodc1.RecordSource = TmpSource;
                        Adodc1.Refresh;
                        DataGrid1.Refresh;

                        if (Adodc1.Recordset.EOF == true)
                        {
                            //MsgBox "没有数据可供导出!"
                            Command1.Enabled = false;
                        }
                        else
                        {
                            Command1.Enabled = true;
                        }


                    }

                应输入 class、delegate、enum、interface 或 struct    
                出现4个这样的错误
                怎么改
                这是一个单项查询的
  • 写回答

1条回答 默认 最新

  • threenewbee 2016-08-19 15:55
    关注

    这些代码必须写在类的定义里,而不能直接放在源代码文件里。
    你的源代码文件应该类似
    using xxx

    namespace xxx
    {
    public class xxx
    {
    private void xxx() //这里才能放函数
    {
    ...
    }

    }
    }

    评论

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符