- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一些奇怪的问题。我使用 MySQL Connector.NET,但 MySqlReader.Read()
有时返回 true,有时返回 false。 MySqlReader.HasRows
在这两种情况下都是正确的,在 VisualStudio 中我可以看到读取器对象包含所有值。
为什么会这样?
这是我的代码:
MySqlCommand sqlCommand = new MySqlCommand(sqlCode, this._conn);
MySqlDataReader rdr = sqlCommand.ExecuteReader();
PopulateMessage("--> " + serverName + ": " + dbName);
int fields = rdr.VisibleFieldCount;
//make headers
int[] fmaxl = new int[fields];
string[] headers = new string[fields];
List<string[]> vals = new List<string[]>();
if (rdr.HasRows)
{
for (int hi = 0; hi < fields; hi++)
{
string val = rdr.GetName(hi);
headers[hi] += val;
fmaxl[hi] = val.Length;
}
while (rdr.HasRows && rdr.Read()) // <-- here the Read() method returns
// false or true sometimes
// while HasRows is true
{
...
EID:rdr
包含例如 99 行的值(在 VS 中检查)并且在第一次调用 Read()
方法时返回 false。感谢 Joachim 让我发布了这条有用的通知。
最佳答案
此 HasRows 属性并非在所有版本的 .net 中。为什么不这样重写您的代码?
boolean firstRow = true;
while (rdr.Read())
{
if (firstRow) { // get the column names, but only once
firstRow = false;
for (int hi = 0; hi < fields; hi++)
{
string val = rdr.GetName(hi);
headers[hi] += val;
fmaxl[hi] = val.Length;
}
}
... //process each row.
}
完成过吨位这类工作后,我知道这很管用。
关于c# - MySQL .Net 连接器 - MySqlReader.Read() 返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17653732/
我想从我的 mysql 数据库中的两个不同变量中检索数据,因此我创建了一个连接和两个读取器,第二个读取器不返回任何结果,但第一个读取器返回任何结果。 public List BCITLIST =
如果可能的话,我必须找到一种在 C# 中执行此操作的方法... 我必须在我的文件夹列表(mysql 表)上循环,并且对于我实例化的每个文件夹,我必须执行另一个查询,但是当我这样做时,它会说:“已经有一
出于某种原因,我无法在谷歌中找到一个很好的答案,为什么这段代码有效: MySqlConnection connection = new MySqlConnection("Databaseyeshuv1
我希望将我的脚本从 Oracle 转换为 Pomelo,我使用 EntityFramework 作为我的脚本,并使用 MySQL 命令和读取器来访问我的 XenForo 安装。转换时,我有一行代码 r
我想检查 MySQLReader 是否已完成查找我的记录。 到目前为止,这段代码帮助我找到了记录。 if reader.HasRows then while reader.Read() /
我有一些奇怪的问题。我使用 MySQL Connector.NET,但 MySqlReader.Read() 有时返回 true,有时返回 false。 MySqlReader.HasRows 在这两
我是一名优秀的程序员,十分优秀!