vb.net - ExecuteNonQuery returns -1 (incorrectly) -
i inherited old vb website uses executenonquery modify passwords. in our production environment, sql server 2008 r2, i've had recent reports of broken functionality. turns out executenonquery returning -1 when in fact data getting updated (a single row). when copied data our dev environment, rows affected 1 expected. have different service packs applied (4xxx vs 6xxx) , wonder if issue? modified code use executescalar inspect rowcount, , working. shouldn't have so. insight? have idea how long has been broken.
here's original code, returns -1 erroneously. not calling stored procedure , there no triggers involved.
dim cmd sqlcommand = new sqlcommand("update usermaster " & _ " set password = @password, lastpasswordchangeddate = @lastpasswordchangeddate " & _ " username = @username , applicationname = @applicationname ", conn) cmd.parameters.add("@password", sqldbtype.varchar, 255).value = createhash(newpwd) cmd.parameters.add("@lastpasswordchangeddate", sqldbtype.datetime).value = datetime.now cmd.parameters.add("@username", sqldbtype.varchar, 255).value = username.trimend cmd.parameters.add("@applicationname", sqldbtype.varchar, 255).value = left(papplicationname, 1) dim rowsaffected integer = 0 try conn.open() rowsaffected = cmd.executenonquery()
this code returns 1 expected:
dim cmd sqlcommand = new sqlcommand("update usermaster " & _ " set password = @password, lastpasswordchangeddate = @lastpasswordchangeddate " & _ " username = @username , applicationname = @applicationname ; select @@rowcount", conn) cmd.parameters.add("@password", sqldbtype.varchar, 255).value = createhash(newpwd) cmd.parameters.add("@lastpasswordchangeddate", sqldbtype.datetime).value = datetime.now cmd.parameters.add("@username", sqldbtype.varchar, 255).value = username.trimend cmd.parameters.add("@applicationname", sqldbtype.varchar, 255).value = left(papplicationname, 1) dim rowsaffected integer = 0 try conn.open() rowsaffected = ctype(cmd.executescalar(), integer)
exceutenonquery
returns -1 stored procedures per msdn documentation.
it return updated records' number in case of statement.
Comments
Post a Comment