Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Sqlite ExecuteReader最大返回_C#_Sql_Sqlite - Fatal编程技术网

C#Sqlite ExecuteReader最大返回

C#Sqlite ExecuteReader最大返回,c#,sql,sqlite,C#,Sql,Sqlite,ExecuteReader可以返回的最大行数是多少?我在一个表中有大约67行,它只返回前20行 以下是我的一部分资料来源: SQLiteConnection sDBConnection = new SQLiteConnection("Data Source=Database.ddb;Version=3"); sDBConnection.Open(); string sqlCom = "SELECT * FROM Table1"; SQLiteCommand scdCommand = new SQ

ExecuteReader
可以返回的最大行数是多少?我在一个表中有大约67行,它只返回前20行

以下是我的一部分资料来源:

SQLiteConnection sDBConnection = new SQLiteConnection("Data Source=Database.ddb;Version=3");
sDBConnection.Open();
string sqlCom = "SELECT * FROM Table1";
SQLiteCommand scdCommand = new SQLiteCommand(sqlCom, sDBConnection);
SQLiteDataReader reader = scdCommand.ExecuteReader();

while(reader.Read())
{
    string Value1 = (string)reader["Col1"];
    bool Value2 = true;
    string Value3 = (string)reader["Col2"];
    object[] row = { Value1, Value2, Value3, Value4, Value5 };
    DataGridView1.Rows.Add(row);
}

reader.Close();
sDBConnection.Close();

当然,while循环中没有的值是在别处定义的。

请尝试按如下方式编辑代码:

SQLiteConnection sDBConnection = new SQLiteConnection("Data Source=Database.ddb;Version=3");
sDBConnection.Open();
string sqlCom = "SELECT * FROM Table1";
SQLiteCommand scdCommand = new SQLiteCommand(sqlCom, sDBConnection);
SQLiteDataReader reader = scdCommand.ExecuteReader();

while(reader.Read())
{
string Value1 = reader["Col1"] != null ? Convert.ToString(reader["Col1"]) : string.Empty;
bool Value2 = true;
string Value3 = reader["Col2"] != null ? Convert.ToString(reader["Col2"]) : string.Empty;
object[] row = { Value1, Value2, Value3 };
DataGridView1.Rows.Add(row);
}

reader.Close();
sDBConnection.Close();

删除Value4和Value5或为其提供默认值使用调试器,可能您有一个导致异常的空值。datareaders没有行限制。如果有最大值,则肯定会超过20。还有别的问题。有例外吗?没有,这就是我困惑的原因。我检查并测试了所有的值,以确保不存在任何空值。表中所有行的
Col1
Col2
都有值吗?就是这样。谢谢你,杰基。我在其中一行中有一个空值,但是调试器没有抛出任何异常,所以我认为这不是问题所在。