M
Michael Lang
I'm trying to use regular expressions to format a SQL command to work with
ODBC. So I need to replace the following:
Update table Set (Name=@Name) Where ID = @ID
with...
Update table Set (Name=?) Where ID = ?
but also keep...
Select @@Identity
unchanged.
I started with...
Regex.Replace(commandText, @"@\w+","?")
but it does not leave the @@Identity alone. So I did this next...
Regex.Replace(commandText, @"[^@]@\w+","?")
But that always removes the character before the single '@' also... such
as...
Update table Set (Name?) Where ID =?
Anyone know how to fix this?
FYI,
usually you create a standard ODbcCommand like this...
cmd = new OdbcCommand("SELECT * FROM Customers " +
"WHERE Country = ? AND City = ?", conn);
However, I have a generic data access DLL that works for SQL or ODBC. The
same code creates one command...
cmd = new GenCommand("SELECT * FROM Customers " +
"WHERE Country = @Country AND City = @City", conn);
The GenCommand class handles creating the appropriate underlying data
provider instance (either SqlCommand or OdbcCommand), and formats the
command text before passing to the constructor or the provider's type. For
those interested, you can see details from link in my signature.
ODBC. So I need to replace the following:
Update table Set (Name=@Name) Where ID = @ID
with...
Update table Set (Name=?) Where ID = ?
but also keep...
Select @@Identity
unchanged.
I started with...
Regex.Replace(commandText, @"@\w+","?")
but it does not leave the @@Identity alone. So I did this next...
Regex.Replace(commandText, @"[^@]@\w+","?")
But that always removes the character before the single '@' also... such
as...
Update table Set (Name?) Where ID =?
Anyone know how to fix this?
FYI,
usually you create a standard ODbcCommand like this...
cmd = new OdbcCommand("SELECT * FROM Customers " +
"WHERE Country = ? AND City = ?", conn);
However, I have a generic data access DLL that works for SQL or ODBC. The
same code creates one command...
cmd = new GenCommand("SELECT * FROM Customers " +
"WHERE Country = @Country AND City = @City", conn);
The GenCommand class handles creating the appropriate underlying data
provider instance (either SqlCommand or OdbcCommand), and formats the
command text before passing to the constructor or the provider's type. For
those interested, you can see details from link in my signature.