kidness123
kidness123
2016-08-19 11:54
采纳率: 0%
浏览 1.0k

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条回答 默认 最新

  • caozhy

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

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

    }
    }

    点赞 评论

相关推荐