ExecuteNonQuery: Connection property has not been initialized
-
28-06-2021 - |
質問
I've seen this question asked here before, but never when Enterprise Library is used. I've used code like the following before and it works fine. What's the problem this time? I get the error on the last line:
Database db = new SqlDatabase(MyConfiguration.Current.ConnectionString);
DbCommand cmd = db.GetStoredProcCommand("AddWorkListItem");
db.AddInParameter(cmd, "@PartNumber", DbType.String, partNumber);
db.AddInParameter(cmd, "@Quantity", DbType.Int32, qty);
db.AddInParameter(cmd, "@WorkListTypeCode", DbType.String, code);
db.AddInParameter(cmd, "@UserKey", DbType.Int32, userKey);
return cmd.ExecuteNonQuery();
解決
Gosh it's been a while but I'm pretty sure you call db.ExecuteNonQuery(cmd)
rather than cmd.ExecuteNonQuery()
. Have you tried that?
所属していません StackOverflow