.net - Parametrized query as String -


in project need log queries executed against database. example can use staff user data here. in class have function generating command parameters follows:

public function sqlupdate(byval conn sqlclient.sqlconnection) sqlclient.sqlcommand implements idbconnected.sqlupdate     dim sqlstatement string = "update persons set active=@act, abbreviation=@abbr, firstname=@first, lastname=@last, " & _                                  "birthday=@bday, email=@email,tel=@tel, fax=@fax, registered=@reg, admin=@adm"     sqlstatement &= " id=" & me.id     dim comm new sqlclient.sqlcommand(sqlstatement, conn)     comm.parameters         .add("@act", sqldbtype.bit).value = me.active         .add("@abbr", sqldbtype.varchar).value = me.abbreviation         .add("@first", sqldbtype.varchar).value = me.firstname         .add("@last", sqldbtype.varchar).value = me.lastname         .add("@bday", sqldbtype.smalldatetime).value = me.birthday         .add("@email", sqldbtype.varchar).value = me.email         .add("@tel", sqldbtype.varchar).value = me.telephone         .add("@fax", sqldbtype.varchar).value = me.fax         .add("@reg", sqldbtype.bit).value = me.registered         .add("@adm", sqldbtype.bit).value = me.administrator     end     return comm end function 

when request command text

comm.commandtext 

then still parametrizid query

update persons set active=@act, abbreviation=@abbr, firstname=@first, lastname=@last, birthday=@bday, email=@email,tel=@tel, fax=@fax, registered=@reg, admin=@adm id=2

off course need query parameters replaced values. there easy way or need program function replacements itsself?

the query goes down server with parameters parameters (which helps security , query plan re-use). there no need ask exist - , doesn't.

personally wouldn't replace them, when logging; append name/value pairs when logging it, i.e. log like:

update persons set active=@act, abbreviation=@abbr, firstname=@first, lastname=@last, birthday=@bday, email=@email,tel=@tel, fax=@fax, registered=@reg, admin=@adm id=2 || @act=1 @abbr=mjg @first=fred ...


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -