我收到了这个错误:
“已经有一个打开的 DataReader 与此命令关联,必须先关闭”
private readonly object _syncRoot = new object();
public void SqlConnect(string server, string db, string user, string pw)
{
lock (_syncRoot)
{
new_conn = new SqlConnection("Server=" + server + ";Database=" + db + ";User Id=" + user + ";Password=" + pw + ";");
new_conn.Open();
}
}
public string ReadString(string query)
{
string strResult = null;
using (SqlCommand command = new SqlCommand(query, new_conn))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
strResult = Convert.ToString(reader[0]);
}
reader.Close();
}
}
return strResult;
}
我找不到该代码有什么问题?