【发布时间】:2019-02-12 06:46:05
【问题描述】:
SqlConnection connection = Connect();
SqlCommand command = new SqlCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = sprocName;
command.Connection = connection;
//loop through the dictionary
foreach (string key in paramList.Keys)
{
command.Parameters.AddWithValue(key, paramList[key]);
}
SqlDataReader dataReader = command.ExecuteReader();
我正在尝试从数据库中读取数据,当我传递相同的参数并执行 SP 时,我得到了正确的结果。但是这里 SqlDataReader dataReader = command.ExecuteReader(); 当我检查时(dataReader.HasRows)它返回 false!
【问题讨论】:
-
这是不可能的......检查你是否在同一个数据库/表上运行
-
您是否检查过您的查询是否确实从数据库返回值?
-
您可能需要致电NextResult。
-
@styx 是的,我已经检查过查询实际上从数据库返回值。
-
能否请您也添加SP?
标签: c# sql-server sqldatareader sqlconnection executereader