因为它是一个使用变量请指教

因为它是一个使用变量请指教

本文介绍了无法分配...因为它是一个使用变量请指教的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此代码中,我在阻塞行中获取错误。请告知如何去做。



In this code im getting Error in the blocked line. Please advise how to go about it.

mconn.Open();
using (SqlCommand msqlcmd = new SqlCommand("select * from table1", dlsmain.dlsconn))
{
    using (SqlDataReader msqldat = msqlcmd.ExecuteReader())
    {
        msqldat.Read();
		//...  
		//... assignments from msqldat
		//...
        msqldat.Close();
        msqlcmd.CommandText = "select * from table2";
        msqldat = msqlcmd.ExecuteReader();		// Error : Cannot assign to msqldat because it is a 'using variable'.
        while (msqldat.Read())
        {
			//...
			//...  Some process using msqldat
			//...
        }
        msqldat.Close();
        msqlcmd.CommandText = "select * from table3";
        msqldat = msqlcmd.ExecuteReader();
        while (msqldat.Read())
        {
			//...
			//... Some process using msqldat
			//...
        }
    }
}
mconn.Close();





我有什么试过:



谷歌搜索错误但没有正确的频道。



What I have tried:

googled for the error but not got right channel.

推荐答案

using (SqlDataReader msqldat = msqlcmd.ExecuteReader())
{
        msqldat.Read();
	//...  
	//... assignments from msqldat
	//...
        //msqldat.Close();
}
msqlcmd.CommandText = "select * from table2";
using (SqlDataReader msqldat = msqlcmd.ExecuteReader())
{
        msqldat = msqlcmd.ExecuteReader();		// Error : Cannot assign to msqldat because it is a 'using variable'.
        while (msqldat.Read())
        {
			//...
			//...  Some process using msqldat
			//...
        }
        //msqldat.Close();
}
msqlcmd.CommandText = "select * from table3";
using (SqlDataReader msqldat = msqlcmd.ExecuteReader())
{
        msqldat = msqlcmd.ExecuteReader();
        while (msqldat.Read())
        {
			//...
			//... Some process using msqldat
			//...
        }
}





希望,它有帮助:)



Hope, it helps :)



You can't change reference once you used in using clause. I don't thing you require using there, its dis-connected.


这篇关于无法分配...因为它是一个使用变量请指教的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-22 09:59