/// <summary> /// 得到一个对象实体 /// </summary> public optionsModel DataRowToModel(DataRow row) { optionsModel model=new optionsModel(); if (row != null) { if(row["nc_opid"]!=null) { model.nc_opid=row["nc_opid"].ToString(); } if(row["nc_qid"]!=null) { model.nc_qid=row["nc_qid"].ToString(); } if(row["nvc_opcontent"]!=null) { model.nvc_opcontent=row["nvc_opcontent"].ToString(); } if(row["bit_isright"]!=null && row["bit_isright"].ToString()!="") { if((row["bit_isright"].ToString()=="1")||(row["bit_isright"].ToString().ToLower()=="true")) { model.bit_isright=true; } else { model.bit_isright=false; } } } return model; }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(optionsModel model) { StringBuilder strSql=new StringBuilder(); strSql.Append("insert into options("); strSql.Append("nc_opid,nc_qid,nvc_opcontent,bit_isright)"); strSql.Append(" values ("); strSql.Append("@nc_opid,@nc_qid,@nvc_opcontent,@bit_isright)"); SqlParameter[] parameters = { new SqlParameter("@nc_opid", SqlDbType.NChar,12), new SqlParameter("@nc_qid", SqlDbType.NChar,10), new SqlParameter("@nvc_opcontent", SqlDbType.NVarChar,2000), new SqlParameter("@bit_isright", SqlDbType.Bit,1)}; parameters[0].Value = model.nc_opid; parameters[1].Value = model.nc_qid; parameters[2].Value = model.nvc_opcontent; parameters[3].Value = model.bit_isright; int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(optionsModel model) { StringBuilder strSql=new StringBuilder(); strSql.Append("update options set "); strSql.Append("nc_qid=@nc_qid,"); strSql.Append("nvc_opcontent=@nvc_opcontent,"); strSql.Append("bit_isright=@bit_isright"); strSql.Append(" where nc_opid=@nc_opid "); SqlParameter[] parameters = { new SqlParameter("@nc_qid", SqlDbType.NChar,10), new SqlParameter("@nvc_opcontent", SqlDbType.NVarChar,2000), new SqlParameter("@bit_isright", SqlDbType.Bit,1), new SqlParameter("@nc_opid", SqlDbType.NChar,12)}; parameters[0].Value = model.nc_qid; parameters[1].Value = model.nvc_opcontent; parameters[2].Value = model.bit_isright; parameters[3].Value = model.nc_opid; int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 得到一个对象实体 /// </summary> public optionsModel GetModel(string nc_opid) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 nc_opid,nc_qid,nvc_opcontent,bit_isright from options "); strSql.Append(" where nc_opid=@nc_opid "); SqlParameter[] parameters = { new SqlParameter("@nc_opid", SqlDbType.NChar,12) }; parameters[0].Value = nc_opid; optionsModel model=new optionsModel(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }