我在C#中有一个方法,它应该从mysql获取一些数据,然后将这些数据插入另一个表中
问题在于,无论我尝试什么,我都会得到another datareader is open
我尝试使用using
声明,但没有成功,也许我做错了。
怎么做?
public void MethodName(List<string> objects)
{
foreach(string Object in objects){
SQLActions.Initialize();
SQLActions.SQL_Open();
MySqlDataReader queryData = SQLActions.SQL_Query("SELECT...query...");
MySqlDataReader objectsData = SQLActions.SQL_Query("Another select....");
SQLActions.SQL_NonQuery("Insert...");
while(queryData.Read()){
SQLActions.SQL_NonQuery("Another Insert...");
}
SQLActions.SQL_Close();
}
}
答案 0 :(得分:2)
您可能正在为DataReader和ExecuteNonQuery使用相同的连接。根据MSDN:http://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.80).aspx
,这不受支持检查一下:
C# mySQL There is already an open DataReader associated
来自Microsoft:
完成使用DataReader对象后,应始终调用Close方法。