• Connecting method


    // sb  sql

     string setting = System.Configuration.ConfigurationManager.AppSettings["ConnectString"].ToString();
                SqlConnection myconn = new SqlConnection(setting);
                myconn.Open();

                SqlCommand cmd = new SqlCommand(sb.ToString(), myconn);

                cmd.ExecuteReader();

    ----------------------------------------

    采用存储过程

      SqlCommand com = new SqlCommand("PR_Indepot", DBHelper.Connectionstrings);
                    com.CommandType = CommandType.StoredProcedure;
                    SqlParameter[] pa ={
                        new SqlParameter("@id",SqlDbType.Int),
                    new SqlParameter("@goodsName",SqlDbType.VarChar,50),
                    new SqlParameter("@type",SqlDbType.VarChar,50),
                    new SqlParameter("@model",SqlDbType.VarChar,50),
                    new SqlParameter("@spec",SqlDbType.VarChar,50),
                    new SqlParameter("@card",SqlDbType.VarChar,50),
                    new SqlParameter("@price",SqlDbType.Money),
                    new SqlParameter("@unit",SqlDbType.VarChar,50),
                    new SqlParameter("@amount",SqlDbType.Int),
                    new SqlParameter("@pay",SqlDbType.Money),
                    new SqlParameter("@bid",SqlDbType.Int),
                    new SqlParameter("@address",SqlDbType.VarChar,50),
                    new SqlParameter("@linkMan",SqlDbType.VarChar,50),
                    new SqlParameter("@phone",SqlDbType.VarChar,50)
                };
                    pa[0].Value = ind.Id;
                    pa[1].Value = ind.GoodsName;
                    pa[2].Value = ind.GoodsType;
                    pa[3].Value = ind.Model;
                    pa[4].Value = ind.Spec;
                    pa[5].Value = ind.Card;
                    pa[6].Value = ind.UnitPrice;
                    pa[7].Value = ind.Unit;
                    pa[8].Value = ind.Amount;
                    pa[9].Value = ind.Pay;
                    pa[10].Value = ind.Bid.Id;
                    pa[11].Value = ind.Address;
                    pa[12].Value = ind.LinkMan;
                    pa[13].Value = ind.Phone;
                    foreach (SqlParameter p in pa)
                    {
                        com.Parameters.Add(p);
                    }

  • 相关阅读:
    C++ sort排序
    ROS1 Qt5 CMake基本配置
    TCP连接connect函数返回错误
    自定义类型与Qt元对象系统
    Vue学习二、基本语法
    TypeScript学习: 十二、TS中的装饰器
    Vue学习四、使用双向数据绑定实现表单操作
    TypeScript学习: 十一、TS中的命名空间
    Vue学习三、事件方法、监听、传值
    TypeScript学习: 十、TypeScript的模块
  • 原文地址:https://www.cnblogs.com/greencolor/p/1724599.html
Copyright © 2020-2023  润新知