Answers for "sqlparameter c# example"

C#
0

sqlparameter c# example

public static bool AddCart(orderinfo item)
        {
            SqlParameter[] parms = new SqlParameter[7];
            parms[0] = new SqlParameter("@id", SqlDbType.VarChar, 20);
            parms[0].Direction = ParameterDirection.Output;
            parms[1] = new SqlParameter("@productid", SqlDbType.NVarChar,50);
            parms[1].Value = item.productid;
            parms[2] = new SqlParameter("@userid", SqlDbType.NVarChar, 50);
            parms[2].Value = item.userid;
            parms[3] = new SqlParameter("adddate", SqlDbType.DateTime);
            parms[3].Value = item.adddate;
            parms[4] = new SqlParameter("@vipprice", SqlDbType.Decimal);
            parms[4].Value = item.vipprice;
            parms[5] = new SqlParameter("@buynum", SqlDbType.Int);
            parms[5].Value =item.buynum;
            parms[6] = new SqlParameter("@cartstate", SqlDbType.Int);
            parms[6].Value = item.cartstate;

            string sql = "exec dbo.www_getno 'usercart',10,@id output " +
                         "Insert into usercart(cartid,productid,userid,adddate,vipprice,buynum,cartstate) VALUES (@id,@productid,@userid,@adddate,@vipprice,@buynum,@cartstate)";
            int result = 0;
            try
            {
                result = SqlHelper.ExecuteNonQuery(SqlHelper.connectionstring, CommandType.Text, sql, parms);
                return result > 0;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
            }
        }
Posted by: Guest on September-03-2021

C# Answers by Framework

Browse Popular Code Answers by Language