• ado.net 插入一条数据


     /// <summary>
            //插入数据
            /// </summary>
            /// <param name="SQLString">计算查询结果语句</param>
            /// <returns>查询结果(object)</returns>
            public  int  ExecuteData(string SQLString, params SqlParameter[] cmdParms)
            {
                string connectionString = "Data Source=192.168.42.97;Initial Catalog=DataCompare;User ID=sa;Password=sa";
                int ret = 0;
                try
                {
                    using (SqlConnection conn = new SqlConnection(connectionString))
                    {
                        conn.Open();
                        using (SqlCommand cmd = conn.CreateCommand())
                        {
                            cmd.Parameters.AddRange(cmdParms);
                            cmd.CommandText = SQLString;
                            ret = cmd.ExecuteNonQuery();
                        }
     
                    }
                }
                catch (Exception ex)
                {
                    ret = 0;
                
                }
                return ret;
            }
     
     
     
      /// <summary>
            /// 增加一条数据
            /// </summary>
            public int Add(InputData model)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into InputData(");
                strSql.Append("code,name,newpric,jys,mtime,datatype,createtime");
                strSql.Append(") values (");
                strSql.Append("@code,@name,@newpric,@jys,@mtime,@datatype,@createtime");
                strSql.Append(") ");
                strSql.Append(";select @@IDENTITY");
                SqlParameter[] parameters = {
                   new SqlParameter("@code", SqlDbType.NVarChar,100) ,            
                            new SqlParameter("@name", SqlDbType.NVarChar,100) ,            
                            new SqlParameter("@newpric", SqlDbType.NVarChar,20) ,            
                            new SqlParameter("@jys", SqlDbType.NVarChar,100) ,            
                            new SqlParameter("@mtime", SqlDbType.DateTime) ,            
                            new SqlParameter("@datatype", SqlDbType.NChar,10) ,            
                            new SqlParameter("@createtime", SqlDbType.DateTime)             
                  
                };
                parameters[0].Value = model.code;
                parameters[1].Value = model.name;
                parameters[2].Value = model.newpric;
                parameters[3].Value = model.jys;
                parameters[4].Value = model.mtime;
                parameters[5].Value = model.datatype;
                parameters[6].Value = model.createtime;
                object obj = ExecuteData(strSql.ToString(), parameters);
                if (obj == null)
                {
                    return 0;
                }
                else
                {
                    return Convert.ToInt32(obj);
                }
            }
  • 相关阅读:
    (转)OpenGL和D3D
    (转)海岸线提取完成, 海浪排岸效果
    (转)perlin噪声函数
    D3D 部分功能测试结论
    (转)学习directx遇到的问题
    D3D Lock Pool
    D3D渲染到纹理
    用Eclipse平台进行c/c++开发
    var读写和function读写,get/set读写效率比较
    flash fps游戏 fps多少为佳
  • 原文地址:https://www.cnblogs.com/puzi0315/p/2628969.html
Copyright © 2020-2023  润新知