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