public static int UpdateInternetPrinter(Model.px_InternetPrinterModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update px_InternetPrinter set "); strSql.Append("IName=@IName,"); strSql.Append("PrintIP=@PrintIP,"); strSql.Append("IAddTime=@IAddTime,"); strSql.Append("IRole=@IRole,"); strSql.Append("IRamark=@IRamark"); strSql.Append(" where IID=@IID"); SqlParameter[] parameters = { new SqlParameter("@IName", SqlDbType.NVarChar), new SqlParameter("@PrintIP", SqlDbType.NVarChar), new SqlParameter("@IAddTime", SqlDbType.DateTime), new SqlParameter("@IRole", SqlDbType.NVarChar), new SqlParameter("@IRamark", SqlDbType.NVarChar), new SqlParameter("@IID", SqlDbType.Int) }; parameters[0].Value = model.IName; parameters[1].Value = model.PrintIP; parameters[2].Value = Convert.ToDateTime(model.IAddTime); parameters[3].Value = model.IRole; parameters[4].Value = model.IRamark; parameters[5].Value = Convert.ToInt32(model.IID); int rows = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, System.Data.CommandType.Text, strSql.ToString(), parameters); return(rows); }
public static int AddInternetPrinter(Model.px_InternetPrinterModel model) { string maxid = @"set identity_insert px_InternetPrinter ON; declare @i int; SELECT @i=max([IID]) FROM [px_InternetPrinter]; if @i is null begin set @i=1 end else begin set @i=@i+1 end; "; StringBuilder strSql = new StringBuilder(); strSql.Append("insert into px_InternetPrinter("); strSql.Append("IID,IName,PrintIP,IAddTime,IRole,IRamark)"); strSql.Append(" values ("); strSql.Append("@i,@IName,@PrintIP,@IAddTime,@IRole,@IRamark)"); SqlParameter[] parameters = { new SqlParameter("@IName", SqlDbType.NVarChar), new SqlParameter("@PrintIP", SqlDbType.NVarChar), new SqlParameter("@IAddTime", SqlDbType.DateTime), new SqlParameter("@IRole", SqlDbType.NVarChar), new SqlParameter("@IRamark", SqlDbType.NVarChar) }; parameters[0].Value = model.IName; parameters[1].Value = model.PrintIP; parameters[2].Value = Convert.ToDateTime(model.IAddTime); parameters[3].Value = model.IRole; parameters[4].Value = model.IRamark; string end = @"set identity_insert px_InternetPrinter OFF"; int rows = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, System.Data.CommandType.Text, maxid + strSql + end, parameters); return(rows); }