Flynn1179
Flynn1179

Reputation: 12075

Is there a generic way of passing a DbType as a parameter

I need to execute this parameterized query, or an equivalent:

ALTER TABLE tableName ADD COLUMN ? ?

with the parameters as the name of the new column, and the data type. For example, if I pass in 'Name' DbType.Double, then it would resolve to:

ALTER TABLE tablename ADD COLUMN Name FLOAT

I can't just create a mapping between DbType and the name of the field type, as the code's working on the IDbConnection interface, not a specific implementation. Is there a generic way of doing this? Right now I've got a separate mapping for each implementation, which is obviously far from ideal.

Upvotes: 1

Views: 315

Answers (1)

D. Lambert
D. Lambert

Reputation: 1304

You're going to have to do this dynamically, and it may make sense to look at a provider-specific translation (so providers can supply their own mappings).

Upvotes: 1

Related Questions