Tuesday, 15 June 2010

parameters - Preparing a Query in VB.NET -



parameters - Preparing a Query in VB.NET -

i have troubles preparing query 2 parameters in vb.net.

this code:

dim username string = loginusername.value dim password string = encryptmd5standard(loginpassword.value) dim valid boolean = false dim connectionstring string = configurationmanager.connectionstrings("myconnectionstring").connectionstring dim querystring string = "select id, user_name, role users user_name = '@user' , paswd = '@pass'" dim ds new dataset() seek using connection new sqlconnection(connectionstring) dim command new sqlcommand(querystring, connection) connection.open() command.commandtext = querystring command.parameters.add("@user", sqldbtype.nvarchar, 15).value = username command.parameters.add("@pass", sqldbtype.nvarchar, 32).value = password dim adapter new sqldataadapter() adapter.selectcommand = command adapter.fill(ds, "login") if ds.tables("login").rows.count > 0 valid = true end if end using grab ex exception errorlabel.text = directcast(getlocalresourceobject("erroredb"), string) & ": " & ex.tostring end seek

but, doing valid value "false", fails row count. used debug , looks table login within ds empty. query works, tried manually in sqlserver replacing parameters , can't understand why have empty results.

what i'm doing wrong?.

you don't need wrap parameters in single quotes, parameter scheme takes care of that.

vb.net parameters

No comments:

Post a Comment