I have a variable list of IDs. I want to update the "Status" column for each of those IDs in an Oracle database. I've searched and have come across the following options:
- OracleDataAdapte开发者_开发百科r - Don't have a DataTable, only IDs
- for loop which contains UPDATE statement (could be thousands of UPDATEs)
- Stored Procedure - Hoping not to have to do this
Any help would be greatly appreciated. Thanks
If you already know the Ids you can build an in clause and do an ExecuteScalar:
update sometable set status = 'Shipped' where sometableid in (10,17,19,20,89)
Check out this thread.
https://forums.oracle.com/forums/thread.jspa?threadID=638673
It talks about using parameter arrays which may be perfect for what you are trying to do.
Thanksk for the replies. I had in mind to do it like the following, I was just concerned with keeping the connection open for so many iterations.
using (OracleConnection oracleConnection = new OracleConnection(connection))
{
oracleConnection.Open();
OracleCommand Command = new OracleCommand();
Command.Connection = oracleConnection;
Command.CommandType = CommandType.Text;
status = "A";
foreach (var memberID in MemberIDs)
{
sqlStatement = " UPDATE " + " ourdbtable" + " Set userstatus = '" + status + "' WHERE " + "memberid= " + memberID;
// command
Command.CommandText = sqlStatement;
Command.ExecuteNonQuery();
}
}
精彩评论