asp.net - Conversion from string to type 'Double' is not valid while updating -


i trying update table row. query seems ok don't understand why error coming

error -

system.invalidcastexception: conversion string "update hospitals set votescount " type 'double' not valid. ---> system.formatexception: input string not in correct format. @ microsoft.visualbasic.compilerservices.conversions.parsedouble(string value, numberformatinfo numberformat) @ microsoft.visualbasic.compilerservices.conversions.todouble(string value, numberformatinfo numberformat) --- end of inner exception stack trace --- @ microsoft.visualbasic.compilerservices.conversions.todouble(string value, numberformatinfo numberformat) @ microsoft.visualbasic.compilerservices.conversions.todouble(string value) @ hospital_details.sendreview_click(object sender, eventargs e) in e:\my web\health saviour\website\website\hospital-details.aspx.vb:line 281

`

dim hospitalid string = request.querystring("hospitalid") dim totalscorefrom integer dim currentcount integer dim newavgrating integer dim currentscore integer dim newvotingcount integer dim votesgiven integer dim newcurrentscore integer                      currentcount = totalvotes.text                     newvotingcount = (val(currentcount) + 1)                     totalscorefrom = newvotingcount * 6 * 10                     votesgiven = val(mrating2) + val(mrating3) + val(mrating4) + val(mrating5) + val(mrating6) + val(mrating7)                     newcurrentscore = val(currentscore) + val(votesgiven)                     newavgrating = newcurrentscore * 10 / totalscorefrom                     'formula avg rating = currentscore * 10 / totalscrorefrom                     dim con new mysqlconnection                     dim query new mysqlcommand                     con.connectionstring = configurationmanager _                     .connectionstrings("conio").connectionstring()                     query.connection = con                     query.commandtext = "update hospitals set votescount = '" + newvotingcount + "', currentavgrating = '" + newavgrating + "', totalscoregiven = '" + newcurrentscore + "' hospitalid = '" + hospitalid + "'"                     query.parameters.addwithvalue("@hospitalid", hospitalid)                     query.parameters.addwithvalue("@votescount", newvotingcount)                     query.parameters.addwithvalue("@newavgrating", newavgrating)                     query.parameters.addwithvalue("@newcurrentscore", newcurrentscore)                     query.executenonquery()                     con.close() 

in given snippet using parameters in wrong way. wont add parameters query, use following:

query.commandtext = "update hospitals set votescount = @votescount," &_                       currentavgrating = @currentavgrating," &_                       totalscoregiven = @totalscoregiven" &_                      newcurrentscore =@newcurrentscore hospitalid = @hospitalid"    query.parameters.addwithvalue("@votescount", newvotingcount) query.parameters.addwithvalue("@currentavgrating ", currentavgrating) query.parameters.addwithvalue("@totalscoregiven", newavgrating) query.parameters.addwithvalue("@newcurrentscore", newcurrentscore) query.parameters.addwithvalue("@hospitalid", hospitalid) 

note : parameters.add() more suitable in case, through can specify parameter type too.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -