/// <summary> /// 更新一条数据 /// </summary> public bool Update(zs.Model.Tbl_Zhuanye model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Tbl_Zhuanye set "); strSql.Append("name=@name,"); strSql.Append("cont=@cont,"); strSql.Append("xueyuanid=@xueyuanid"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.VarChar, 80), new SqlParameter("@cont", SqlDbType.VarChar), new SqlParameter("@xueyuanid", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.name; parameters[1].Value = model.cont; parameters[2].Value = model.xueyuanid; 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(zs.Model.Tbl_Zhuanye model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Tbl_Zhuanye("); strSql.Append("name,cont,xueyuanid)"); strSql.Append(" values ("); strSql.Append("@name,@cont,@xueyuanid)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.VarChar, 80), new SqlParameter("@cont", SqlDbType.VarChar), new SqlParameter("@xueyuanid", SqlDbType.Int, 4) }; parameters[0].Value = model.name; parameters[1].Value = model.cont; parameters[2].Value = model.xueyuanid; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtname.Text.Trim().Length == 0) { strErr += "name不能为空!\\n"; } if (this.txtcont.Text.Trim().Length == 0) { strErr += "cont不能为空!\\n"; } if (!PageValidate.IsNumber(txtxueyuanid.Text)) { strErr += "xueyuanid格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string name = this.txtname.Text; string cont = this.txtcont.Text; int xueyuanid = int.Parse(this.txtxueyuanid.Text); zs.Model.Tbl_Zhuanye model = new zs.Model.Tbl_Zhuanye(); model.name = name; model.cont = cont; model.xueyuanid = xueyuanid; zs.BLL.Tbl_Zhuanye bll = new zs.BLL.Tbl_Zhuanye(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
private void ShowInfo(int id) { zs.BLL.Tbl_Zhuanye bll = new zs.BLL.Tbl_Zhuanye(); zs.Model.Tbl_Zhuanye model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.lblname.Text = model.name; this.lblcont.Text = model.cont; this.lblxueyuanid.Text = model.xueyuanid.ToString(); }
/// <summary> /// 得到一个对象实体 /// </summary> public zs.Model.Tbl_Zhuanye GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,name,cont,xueyuanid from Tbl_Zhuanye "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; zs.Model.Tbl_Zhuanye model = new zs.Model.Tbl_Zhuanye(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["name"] != null && ds.Tables[0].Rows[0]["name"].ToString() != "") { model.name = ds.Tables[0].Rows[0]["name"].ToString(); } if (ds.Tables[0].Rows[0]["cont"] != null && ds.Tables[0].Rows[0]["cont"].ToString() != "") { model.cont = ds.Tables[0].Rows[0]["cont"].ToString(); } if (ds.Tables[0].Rows[0]["xueyuanid"] != null && ds.Tables[0].Rows[0]["xueyuanid"].ToString() != "") { model.xueyuanid = int.Parse(ds.Tables[0].Rows[0]["xueyuanid"].ToString()); } return(model); } else { return(null); } }