ExecuteNonQuery requires an open and available Connection. The connection's current state is closed

后端 未结 5 1111
情书的邮戳
情书的邮戳 2021-02-07 11:55

ExecuteNonQuery requires an open and available Connection. The connection\'s current state is closed.

What am I doing wrong here? I\'m assuming you can

5条回答
  •  生来不讨喜
    2021-02-07 12:24

    You're closing the connection rdr.Close(); and never re-opening it before calling ExecuteNonQuery().

    You don't actually need to close it at all if it's wrapped in a using as the call to Dispose() will automatically close the connection for you.

提交回复
热议问题