尝试从DataReader读取时,Invalid attempt to read when Reader is closed在我的duplicateNameCheck方法中获取异常。我不知道为什么。任何帮助是极大的赞赏!public static MySqlConnection GetSqlConnection() { MySqlConnection connection = new MySqlConnection(connectionString); return connection;}public static MySqlDataReader ExecuteReader(string sqlQuery, MySqlConnection connection) { using (MySqlCommand command = new MySqlCommand(sqlQuery, connection)) { try { connection.Open(); MySqlDataReader sqlReader = command.ExecuteReader(); return sqlReader; } catch (Exception ex) { MessageBox.Show(ex.Message); return null; } }}public static bool duplicateNameCheck(string inName) { String sqlQuery = "SELECT * FROM Account"; using (MySqlDataReader sqlReader = SQLHelper.ExecuteReader(sqlQuery, SQLHelper.GetSqlConnection())) { while (sqlReader.Read()) { if (inName.Equals(sqlReader[1].ToString(), StringComparison.InvariantCultureIgnoreCase)) { return true; } } } return false; }
- 1 回答
- 0 关注
- 435 浏览
添加回答
举报
0/150
提交
取消