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