/// <summary> /// 增加一条数据 /// </summary> public int Add(abc.Model.Model.Users model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Users("); strSql.Append("UserName,Pwd,Enabled,CreateTime)"); strSql.Append(" values ("); strSql.Append("SQL2012UserName,SQL2012Pwd,SQL2012Enabled,SQL2012CreateTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("SQL2012UserName", SqlDbType.VarChar, 255), new SqlParameter("SQL2012Pwd", SqlDbType.VarChar, 255), new SqlParameter("SQL2012Enabled", SqlDbType.Int, 4), new SqlParameter("SQL2012CreateTime", SqlDbType.DateTime) }; parameters[0].Value = model.UserName; parameters[1].Value = model.Pwd; parameters[2].Value = model.Enabled; parameters[3].Value = model.CreateTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public abc.Model.Model.Users DataRowToModel(DataRow row) { abc.Model.Model.Users model = new abc.Model.Model.Users(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["UserName"] != null) { model.UserName = row["UserName"].ToString(); } if (row["Pwd"] != null) { model.Pwd = row["Pwd"].ToString(); } if (row["Enabled"] != null && row["Enabled"].ToString() != "") { model.Enabled = int.Parse(row["Enabled"].ToString()); } if (row["CreateTime"] != null && row["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(row["CreateTime"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(abc.Model.Model.Users model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Users set "); strSql.Append("Pwd=SQL2012Pwd,"); strSql.Append("Enabled=SQL2012Enabled,"); strSql.Append("CreateTime=SQL2012CreateTime"); strSql.Append(" where Id=SQL2012Id"); SqlParameter[] parameters = { new SqlParameter("SQL2012Pwd", SqlDbType.VarChar, 255), new SqlParameter("SQL2012Enabled", SqlDbType.Int, 4), new SqlParameter("SQL2012CreateTime", SqlDbType.DateTime), new SqlParameter("SQL2012Id", SqlDbType.Int, 4), new SqlParameter("SQL2012UserName", SqlDbType.VarChar, 255) }; parameters[0].Value = model.Pwd; parameters[1].Value = model.Enabled; parameters[2].Value = model.CreateTime; parameters[3].Value = model.Id; parameters[4].Value = model.UserName; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public abc.Model.Model.Users GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,UserName,Pwd,Enabled,CreateTime from Users "); strSql.Append(" where Id=SQL2012Id"); SqlParameter[] parameters = { new SqlParameter("SQL2012Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; abc.Model.Model.Users model = new abc.Model.Model.Users(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }