/// <summary> /// 得到一个对象实体 /// </summary> public Model.tbAnswer GetModelTran(int id, SqlTransaction transaction) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, chapterid, ques, ans, diff, selectcount, rightcount, questype "); strSql.Append(" from tbAnswer "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Util.MyUtil.PrintSql(strSql.ToString()); Model.tbAnswer model = new Model.tbAnswer(); DataSet ds = SQLHelper.ExecuteDataset(transaction, CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["chapterid"].ToString() != "") { model.chapterid = int.Parse(ds.Tables[0].Rows[0]["chapterid"].ToString()); } model.ques = ds.Tables[0].Rows[0]["ques"].ToString(); model.ans = ds.Tables[0].Rows[0]["ans"].ToString(); if (ds.Tables[0].Rows[0]["diff"].ToString() != "") { model.diff = int.Parse(ds.Tables[0].Rows[0]["diff"].ToString()); } if (ds.Tables[0].Rows[0]["selectcount"].ToString() != "") { model.selectcount = int.Parse(ds.Tables[0].Rows[0]["selectcount"].ToString()); } if (ds.Tables[0].Rows[0]["rightcount"].ToString() != "") { model.rightcount = int.Parse(ds.Tables[0].Rows[0]["rightcount"].ToString()); } if (ds.Tables[0].Rows[0]["questype"].ToString() != "") { model.questype = int.Parse(ds.Tables[0].Rows[0]["questype"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.tbAnswer model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tbAnswer set "); strSql.Append(" chapterid = @chapterid , "); strSql.Append(" ques = @ques , "); strSql.Append(" ans = @ans , "); strSql.Append(" diff = @diff , "); strSql.Append(" selectcount = @selectcount , "); strSql.Append(" rightcount = @rightcount , "); strSql.Append(" questype = @questype "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@chapterid", SqlDbType.Int, 4), new SqlParameter("@ques", SqlDbType.NVarChar, 200), new SqlParameter("@ans", SqlDbType.NVarChar, 500), new SqlParameter("@diff", SqlDbType.Int, 4), new SqlParameter("@selectcount", SqlDbType.Int, 4), new SqlParameter("@rightcount", SqlDbType.Int, 4), new SqlParameter("@questype", SqlDbType.Int, 4) }; parameters[0].Value = model.id; parameters[1].Value = model.chapterid; parameters[2].Value = model.ques; parameters[3].Value = model.ans; parameters[4].Value = model.diff; parameters[5].Value = model.selectcount; parameters[6].Value = model.rightcount; parameters[7].Value = model.questype; Util.MyUtil.PrintSql(strSql.ToString()); int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int AddTran(Model.tbAnswer model, SqlTransaction transaction) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tbAnswer("); strSql.Append("chapterid,ques,ans,diff,selectcount,rightcount,questype"); strSql.Append(") values ("); strSql.Append("@chapterid,@ques,@ans,@diff,@selectcount,@rightcount,@questype"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@chapterid", SqlDbType.Int, 4), new SqlParameter("@ques", SqlDbType.NVarChar, 200), new SqlParameter("@ans", SqlDbType.NVarChar, 500), new SqlParameter("@diff", SqlDbType.Int, 4), new SqlParameter("@selectcount", SqlDbType.Int, 4), new SqlParameter("@rightcount", SqlDbType.Int, 4), new SqlParameter("@questype", SqlDbType.Int, 4) }; parameters[0].Value = model.chapterid; parameters[1].Value = model.ques; parameters[2].Value = model.ans; parameters[3].Value = model.diff; parameters[4].Value = model.selectcount; parameters[5].Value = model.rightcount; parameters[6].Value = model.questype; object obj = SQLHelper.ExecuteScalar(transaction, CommandType.Text, strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } Util.MyUtil.PrintSql(strSql.ToString()); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.tbAnswer GetModelTran(int id ,SqlTransaction transaction) { StringBuilder strSql=new StringBuilder(); strSql.Append("select id, chapterid, ques, ans, diff, selectcount, rightcount, questype "); strSql.Append(" from tbAnswer "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; Util.MyUtil.PrintSql(strSql.ToString()); Model.tbAnswer model=new Model.tbAnswer(); DataSet ds=SQLHelper.ExecuteDataset(transaction,CommandType.Text, strSql.ToString(), parameters); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["id"].ToString()!="") { model.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if(ds.Tables[0].Rows[0]["chapterid"].ToString()!="") { model.chapterid=int.Parse(ds.Tables[0].Rows[0]["chapterid"].ToString()); } model.ques= ds.Tables[0].Rows[0]["ques"].ToString(); model.ans= ds.Tables[0].Rows[0]["ans"].ToString(); if(ds.Tables[0].Rows[0]["diff"].ToString()!="") { model.diff=int.Parse(ds.Tables[0].Rows[0]["diff"].ToString()); } if(ds.Tables[0].Rows[0]["selectcount"].ToString()!="") { model.selectcount=int.Parse(ds.Tables[0].Rows[0]["selectcount"].ToString()); } if(ds.Tables[0].Rows[0]["rightcount"].ToString()!="") { model.rightcount=int.Parse(ds.Tables[0].Rows[0]["rightcount"].ToString()); } if(ds.Tables[0].Rows[0]["questype"].ToString()!="") { model.questype=int.Parse(ds.Tables[0].Rows[0]["questype"].ToString()); } return model; } else { return null; } }