我正在尝试在C#
Winforms中运行以下代码段.这段代码适用于pgsql 2.2.6适配器.为了与pgsql3.0.5适配器一起正常工作,可以进行哪些更正?谢谢.
- NpgsqlConnection conn = new NpgsqlConnection(MainForm2.MyConString);
- {
- conn.Open();
- using (NpgsqlCommand cmd = new NpgsqlCommand("SELECT rfid,name,sc_id from passenger ORDER by name",conn))
- {
- NpgsqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- var obj = new PassengerClass
- {
- RFID = dr.GetString(0),Name = dr.GetString(1),sc_id = dr.GetInt32(2)
- };
- s = dr.GetString(0);
- try { ret.Add(s,obj); }
- catch (Exception ex) { SM.Debug("Fail to add RFID Name in hash RFID:" + s + ex.ToString()); }
- }
- }
- MainForm2.PassHash = ret;
- try
- {
- using (NpgsqlCommand cmd = new NpgsqlCommand(string.Format("UPDATE place set useridx ={0} where useridx=0",MainForm2.userIDX),conn))
- cmd.ExecuteNonQuery();
- using (NpgsqlCommand cmd = new NpgsqlCommand(string.Format("UPDATE zonename set useridx ={0} where useridx=0",conn))
- cmd.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- SM.Debug("Error on update users IDX for place and zone with value 0 :" + ex.ToString());
- }
所以,在第二个命令语句中,它给出了以下错误:
A first chance exception of type ‘System.InvalidOperationException’
occurred in Npgsql.dllAdditional information: An operation is already in progress.