我的应用程序停止工作。我测试了我的存储过程,它确实返回了 3 行(太大而无法在此处重新发布)。在 Visual Studio 的输出中它之后说:
(1 row(s) affected)
(3 row(s) returned)
@RETURN_VALUE = 0
Finished running [dbo].[GetCaseDocumentFile].
为什么我不能将它放入名为dtResult 的数据表中?命令 sqlDataAdapter.Fill(dtResult) 应该可以做到。相反,我在 Debug模式下查看它时得到 {}。
string connectionString = @"Data Source=34.56.55.251;Initial Catalog=DBXXX;User ID=xx;Password=XXXXXXXX;";
string queryString = "GetCaseDocumentFile";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.AddWithValue("@key", 200012);
connection.Open();
// Works! Three lines are returned.
SqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
Console.WriteLine(String.Format("{0}, {1}",
reader[0], reader[1]));
}
}
finally
{
reader.Close();
}
// Does not work! dtResult remains empty. {}
DataTable dtResult = new DataTable();
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(command);
sqlDataAdapter.Fill(dtResult);
DataTable result = dtResult;
}
更新:
没关系。这确实有效。这是我的测试代码和我认为我的真实代码所做的。但我想我在实际代码中忽略了一些东西。
最佳答案
你在你的程序中没有设置计数吗??
设置无计数;
关于c# - 我的存储过程返回了一些东西,但是 sqlDataAdapter.Fill 将数据表留空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5511374/