• 排球比赛积分程序


    一、计划

    二、界面布局及代码

        class SqlHelper

        {//获取连接字符串

            private static readonly string constr = ConfigurationManager.ConnectionStrings["connectionStr"].ConnectionString;

            //ExecuteNonQuery()方法

            //ExecuteScalar()方法

            //ExecuteReader()方法

            //ExecuteDataTable()方法

             

            public static int ExecuteNonQuery(string sql, params SqlParameter[] pms)

            {

                //使用using关键字定义一个范围,在范围结束时骸自动调用这个类实例的Dispose处理对象

                using (SqlConnection con = new SqlConnection(constr))

                {

                    //创建执行DSql命令对象

                    using (SqlCommand cmd = new SqlCommand(sql, con))

                    {

                        //判断是否传递了sql参数

                        if (pms != null)

                        {

                            //讲参数添加到Parameters集合中

                            cmd.Parameters.AddRange(pms);

                        }

                        con.Open();

                        return cmd.ExecuteNonQuery();

                    }

                }

            }

            //执行返回单个值的

            public static object ExecuteScalar(string sql, params SqlParameter[] pms)

            { 

                using (SqlConnection con = new SqlConnection(constr))

                {

                    using (SqlCommand cmd = new SqlCommand(sql, con))

                    {

                        if (pms != null)

                        {

                            cmd.Parameters.AddRange(pms);

                        }

                        con.Open();

                        return cmd.ExecuteScalar();

                    }

                }

                

            }

            //执行返回SqlDataReader

            public static SqlDataReader ExecuteReader(string sql, params SqlParameter[] pms)

            {

                SqlConnection con = new SqlConnection(constr);

                

                    using (SqlCommand cmd = new SqlCommand(sql, con))

                    {

                        if (pms != null)

                        {

                            cmd.Parameters.AddRange(pms);

                        }

                        try

                        {

                            con.Open();

                            return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

                        }

                        catch (Exception)

                        {

                            con.Close();

                            con.Dispose();

                            throw;

                        }

                    }

            }

            //执行返回DataTable

            public static DataTable ExecuteDataTable(string sql, params SqlParameter[] pms)

            {

                DataTable dt = new DataTable();

                using (SqlDataAdapter adapter = new SqlDataAdapter(sql, constr))

                {

                    if (pms != null)

                    {

                        adapter.SelectCommand.Parameters.AddRange(pms);

                    }

                    adapter.Fill(dt);

                }

                return dt;

            }

        }

      class Info

        {

            public string Name { get; set; }

            public int First { get; set; }

            public int Second { get; set; }

            public int Third { get; set; }

            public int Fourth { get; set; }

            public int Fifth { get; set; }

            public int Score { get; set; }

           

        }

         private void Select1_Click_1(object sender, EventArgs e)

       {

               string sql = "select * from Bifen where Name=@Name";

                SqlParameter[] paras = new SqlParameter[]

                {

                    new SqlParameter("@Name",Name);   

                };

                using (SqlDataReader reader = SqlHelper.ExecuteReader(sql, paras))

                {

                    if (reader.Read())

                    {

                       Info bf = new Info();

                       bf.Name = (string)reader["Name"];

                       bf.Second = reader.GetInt32(1);

                       bf.Third = reader.GetInt32(2);

                       bf.Fourth = reader.GetInt32(3);

                       bf.Fifth = reader.GetInt32(4);

                       bf.Score = reader.GetInt32(5);               

                    }

                }

             }   

        }

    private void button1_Click(object sender, EventArgs e)

    {

    if(comboBox1.selectIndex==0)

    {

    txtbox1.Text = bf.first.ToString();

    }

    if(comboBox1.selectIndex==1)

    {

    txtbox1.Text = bf.second.ToString();

    }

    if(comboBox1.selectIndex=2)

    {

    txtbox1.Text = bf.third.ToString();

    }

    if(comboBox1.selectIndex=3)

    {

    txtbox1.Text = bf.fourth.ToString();

    }

    if(comboBox1.selectIndex=4)

    {

    txtbox1.Text = bf.fifth.ToString();

    }

    private void button2_Click(object sender, EventArgs e)

    {

        txtbox2.Text = bf.score.ToString();

    }     

  • 相关阅读:
    剑指OFFER----面试题17- 打印从1到最大的n位数
    剑指OFFER----面试题16. 数值的整数次方
    剑指OFFER----面试题15. 二进制中1的个数
    剑指OFFER----面试题14- II. 剪绳子II
    07 多层if判断
    08 while循环
    06 if 流程控制
    03 身份运算符、逻辑运算符
    04 位运算符、运算符优先级
    02 赋值运算符、成员运算符
  • 原文地址:https://www.cnblogs.com/liangyaxin/p/6194729.html
Copyright © 2020-2023  润新知