你好有没有办法同时使用两个sqldatareader?
我正在编写程序
我得到了错误,因为我同时使用了 2 个阅读器
代码示例
SqlCommand LoadSilk = new SqlCommand("SELECT silk_own FROM SK_Silk WHERE JID = (SELECT JID FROM TB_User WHERE StrUserID = '"+ comboBox1.Text +"')", Connection);
SqlDataReader SilkReader = LoadSilk.ExecuteReader();
SqlCommand LoadCharacter = new SqlCommand("SELECT * FROM SRO_VT_SHARD.DBO._Char WHERE CharID IN (SELECT CharID FROM SRO_VT_SHARD.DBO._User WHERE UserJID = "+ JID +")", Connection);
SqlDataReader CharacterReader = LoadCharacter.ExecuteReader();
try
{
SilkReader.Read();
textBox5.Text = SilkReader[0].ToString();
Silk = SilkReader[0].ToString();
dataGridView1.Enabled = true;
button2.Enabled = true;
while (CharacterReader.Read()) {
dataGridView1.Rows.Add(CharacterReader["CharID"].ToString(), CharacterReader["CharName16"].ToString(), CharacterReader["CurLevel"].ToString());
}
log(comboBox1.Text + " account data loaded");
}
catch (Exception ex) {
log(ex.Message);
MessageBox.Show("Error");
} finally {
SilkReader.Close();
CharacterReader.Close();
}
它给了我那个错误
已经有一个与此命令关联的打开的 DataReader,必须先关闭它。