/// <summary> /// 增加一条数据 /// </summary> public int Add(Dianda.Model.Cash_DetailNameList model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Cash_DetailNameList("); strSql.Append("DetailName,OrderNum)"); strSql.Append(" values ("); strSql.Append("@DetailName,@OrderNum)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@DetailName", SqlDbType.VarChar, 50), new SqlParameter("@OrderNum", SqlDbType.Int, 4) }; parameters[0].Value = model.DetailName; parameters[1].Value = model.OrderNum; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Dianda.Model.Cash_DetailNameList model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Cash_DetailNameList set "); strSql.Append("DetailName=@DetailName,"); strSql.Append("OrderNum=@OrderNum"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@DetailName", SqlDbType.VarChar, 50), new SqlParameter("@OrderNum", SqlDbType.Int, 4), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.DetailName; parameters[1].Value = model.OrderNum; parameters[2].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Dianda.Model.Cash_DetailNameList GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,DetailName,OrderNum from Cash_DetailNameList "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; Dianda.Model.Cash_DetailNameList model = new Dianda.Model.Cash_DetailNameList(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } if (ds.Tables[0].Rows[0]["DetailName"] != null && ds.Tables[0].Rows[0]["DetailName"].ToString() != "") { model.DetailName = ds.Tables[0].Rows[0]["DetailName"].ToString(); } if (ds.Tables[0].Rows[0]["OrderNum"] != null && ds.Tables[0].Rows[0]["OrderNum"].ToString() != "") { model.OrderNum = int.Parse(ds.Tables[0].Rows[0]["OrderNum"].ToString()); } return(model); } else { return(null); } }