asp.net高级教程(三)-实战篇(5) //如果用户名中包含单引号则抛出一个异常 if (a_strUserName.IndexOf("'") != -1) { throw(new Exception("用户名包含非法字符")) ; } bool bExists = false ; MyConnection myConn = new MyConnection() ; try { myConn.Open() ; SQLCommand myCommand = new SQLCommand() ; myCommand.ActiveConnection = myConn ; myCommand.CommandText = "select * from BBSUser where UserName='" + a_strUserName + "'"; SQLDataReader myReader ; myCommand.Execute(out myReader) ; if (myReader.Read())