C# 填写datatable ein.NET 4.5时类似ADO.NET缓存的行为

C# 填写datatable ein.NET 4.5时类似ADO.NET缓存的行为,c#,.net,ado.net,datatable,.net-4.5,C#,.net,Ado.net,Datatable,.net 4.5,我有一个循环代码,它使用存储过程填充数据表。存储过程生成的行集总是不同的,因为它是每次调用时更新的计数器 请注意,对存储过程的每次调用都使用完全相同的参数完成 我已经在SQLManagerStudio上对其进行了测试,效果很好。在.NET3.5中,它也运行良好 for (int i = 0; i < total; i++) { SqlCommand cmd= new SqlCommand("MyStoredProcedure", cn); cmd.Comm

我有一个循环代码,它使用存储过程填充数据表。存储过程生成的行集总是不同的,因为它是每次调用时更新的计数器

请注意,对存储过程的每次调用都使用完全相同的参数完成

我已经在SQLManagerStudio上对其进行了测试,效果很好。在.NET3.5中,它也运行良好

for (int i = 0; i < total; i++)
   {
       SqlCommand cmd= new SqlCommand("MyStoredProcedure", cn);
       cmd.CommandType = CommandType.StoredProcedure;
       cmd.Parameters.AddWithValue("@param1", Convert.ToInt32(Textbox1.Text));

       string AlwaysDifferentCounter = "";
       MyDatatable.Clear();
       MyDatatable = cmd.Fill();


       AlwaysDifferentCounter = MyDatatable.Rows[0]["Counter"].ToString();
       //AlwaysDifferentCounter value always is the same 

   }

为什么会发生这种情况?Framework 4.5中是否存在缓存行为?

为什么要使用DataTable返回单个值?字符串计数器=(字符串)SQLcmd2.ExecuteScalar()@因为我返回了更多的数据,这只是一个例子。
       AlwaysDifferentCounter = MyDatatable.Parameters["@Counter"].Value.ToString();
       //AlwaysDifferentCounter now it has a different value on each call