日期:2014-05-17 浏览次数:20523 次
public int RunSQL(string cmdText, SqlParameter[] prams) { SqlCommand cmd = CreateSQLCommand(cmdText, prams); try { cmd.ExecuteNonQuery(); //return (int)cmd.ExecuteNonQuery(); 这句我写的,觉得还好写啊 } catch (Exception ex) { throw new Exception(ex.Message); } finally { Close(); } return (int)cmd.Parameters[RETURNVALUE].Value; //我上面的语句可以完全替换吗?有什么区别啊? }
public bool Add_User(User user) { SqlParameter[] paramList ={ sqlHelper.CreateInParam("@uid",SqlDbType.VarChar,50,user.uid), sqlHelper.CreateInParam("@pwd",SqlDbType.VarChar,50,user.pwd), sqlHelper.CreateInParam("@name",SqlDbType.VarChar,50,user.name), }; string sql = "insert into tt_User (uid,pwd,name) values (@uid,@pwd,@name)"; int count = sqlHelper.RunSQL(sql, paramList);//不知道参数都是这么设置的吗?也添加了记录,就是返回的值不对,判断不对 if (count > 0) { return true; } else { return false; } }