locked
DbCommand and unnamed parameters RRS feed

  • Question

  • I'm using DbProviderFactory to create a connection. With this connection I create a DbCommand. I add DbParameters and execute the query.
    This way it doesn't matter if the datasource is Sql Server, Access, Oracle etc.
    But there's a problem. When I create a connection for an Odbc database I need to use unnamed parameters, but when I create a connection for Sql Server I need to use named parameters. I thought using DbParameter would solve the problem for me, but it doesn't.
    So not knowing which datasource I'm dealing with I can't create the commandtext, because I don't know if I need named parameters or not. So I don't know if the commandtext needs to look like this (odbc):
    UPDATE Humres SET fullname = ?
    Or like this (sql server):
    UPDATE Humres SET fullname = @fullname
    Or like this (oracle):
    UPDATE Humres SET fullname = :fullname

    So how can I fix this?
    Thursday, August 2, 2007 1:03 PM

Answers

  • Here's what MSDN says:
    "The factory model is not helpful for creating parameterized DbCommand and DbDataAdapter objects. You will need to branch in your code to create parameters that are tailored to your data provider."

    However, I did find this:
    http://www.theproblemsolver.nl/dbproviderfactory/index.htm

    Perhaps that will help. Good luck.
    Thursday, August 2, 2007 5:53 PM

All replies

  • Here's what MSDN says:
    "The factory model is not helpful for creating parameterized DbCommand and DbDataAdapter objects. You will need to branch in your code to create parameters that are tailored to your data provider."

    However, I did find this:
    http://www.theproblemsolver.nl/dbproviderfactory/index.htm

    Perhaps that will help. Good luck.
    Thursday, August 2, 2007 5:53 PM
  • Thanks a lot, that was very helpful.
    Thursday, August 2, 2007 7:01 PM