Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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# 是否跳过SqlDataReader.ExecuteReader?_C#_Sql Server - Fatal编程技术网

C# 是否跳过SqlDataReader.ExecuteReader?

C# 是否跳过SqlDataReader.ExecuteReader?,c#,sql-server,C#,Sql Server,我有和这里一样的问题: 读卡器永远不会被执行。 我试图从本地数据库读取数据。可能是什么?数据库不是空的,但我从未收到“hello from foo” 它还说阅读器没有行 SqlConnection myConn = new SqlConnection("Data Source=(LocalDB)\\v11.0;Integrated Security=True"); SqlCommand comm = new SqlCommand("select * from employees;",myCo

我有和这里一样的问题: 读卡器永远不会被执行。
我试图从本地数据库读取数据。可能是什么?数据库不是空的,但我从未收到
“hello from foo”

它还说阅读器没有行

SqlConnection myConn = new SqlConnection("Data Source=(LocalDB)\\v11.0;Integrated Security=True");


SqlCommand comm = new SqlCommand("select * from employees;",myConn);

myConn.Open();
SqlDataReader reader = comm.ExecuteReader();


while (reader.Read())
{
    MessageBox.Show(reader[0].ToString())
    MessageBox.Show("hello from foo");
}
if (reader.HasRows)
{
    MessageBox.Show("reader.hasRows == true !");
}
else
{
    MessageBox.Show("reader.hasRows == FALSE !");
}

myConn.Close();
更新:
我已将连接字符串更改为:“Data Source=my_server\u name;Initial Catalog=employees;Integrated Security=True”现在可以工作了,非常感谢。

您确定该表名为employees而不是employees吗?如果您没有收到由错误名称引起的异常,则您的数据库表“employees”为空。或者您正在读取的数据库与您正在查看的数据库不同。请尝试打开连接,然后再给它
comm
,并尝试将
while(reader.Read())
放入
if(reader.HasRows)中
如果此代码位于窗口的.Load事件中,并且在64位计算机上运行,则它引发的任何异常都将被隐藏,除非为CLR异常启用“抛出时中断”。我已尝试了您的所有建议,但读卡器仍然没有执行,只是跳过了它。我仍然得到消息,它没有行,数据库不是空的。