/// <summary> /// 增加一条数据 /// </summary> public int Add(M_province model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into province("); strSql.Append("provinceID,province)"); strSql.Append(" values ("); strSql.Append("@provinceID,@province)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@provinceID", SqlDbType.Int, 4), new SqlParameter("@province", SqlDbType.VarChar, 200) }; parameters[0].Value = model.provinceID; parameters[1].Value = model.province; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(M_province model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update province set "); strSql.Append("provinceID=@provinceID,"); strSql.Append("province=@province"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@provinceID", SqlDbType.Int, 4), new SqlParameter("@province", SqlDbType.VarChar, 200), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.provinceID; parameters[1].Value = model.province; parameters[2].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public void insert_(M_province entity) { sqlite_conn = connector.con(); sqlite_conn.Open(); SQLiteCommand comm = sqlite_conn.CreateCommand(); comm.CommandText = @"INSERT INTO `Province` ( `Province_name` ) VALUES ( @province );"; comm.Parameters.AddWithValue("@province", entity.province_name); comm.ExecuteNonQuery(); sqlite_conn.Close(); MessageBox.Show("Succesfully Added", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// 得到一个对象实体 /// </summary> public M_province DataRowToModel(DataRow row) { M_province model = new M_province(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["provinceID"] != null && row["provinceID"].ToString() != "") { model.provinceID = int.Parse(row["provinceID"].ToString()); } if (row["province"] != null) { model.province = row["province"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public M_province GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,provinceID,province from province "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; M_province model = new M_province(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(M_province model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(M_province model) { return(dal.Add(model)); }