• 排球计分程序(现场记分员)


    1.计划

    估计需要两周

    2.需求分析

    作为一名现场记分员,我希望详细记录比赛现场比分增长情况,以便观众及运动员、教练员及时掌握比赛状况。

    3.设计文档

    当用户进入程序时,可以看到以往队员的分数,和得分类型双击表格。

    4.具体代码

    public static class SqlHelper
        {

            //1.连接字符串
            private static readonly string constr = ConfigurationManager.ConnectionStrings["player"].ConnectionString;

            //2.执行增删改的
            public static int ExecuteNonQuery(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.ExecuteNonQuery();
                    }
                }
            }

            //3.执行返回单个值的
            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();
                    }
                }
            }

            //4.执行返回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;
                    }
                }
            }

            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;
            }


    代码测试:

    添加功能和删除功能能用

    总结:

    勤加练习

  • 相关阅读:
    SpringMVC @RequestBody请求参数在postman中的请求
    git rm -r --cached 去掉已经托管在git上的文件
    shiro源码解析--------欢迎指出错误地方,还有一起讨论一下ShiroFilterFactoryBean配置过滤URL规则
    如何用Tomcat部署前端静态文件
    用HTML 格式导出Excel
    csv和excel的区别
    使用HttpOnly提升Cookie安全性
    asp.net core 如何在Controller获取配置文件的值
    Find Out What Your Entity Framework Query Is Really Doing
    鸡汤
  • 原文地址:https://www.cnblogs.com/zxcv5678/p/6568456.html
Copyright © 2020-2023  润新知