c# - convert type 'object' to 'System.Data.SqlClient.SqlCommand Error -


cannot implicitly convert type 'object' 'system.data.sqlclient.sqlcommand'. explicit conversion exists (are missing cast?)

i got error while creating usercontrol

it in code.

  protected void gvdetails_rowupdating(object sender, gridviewupdateeventargs e) { int slno = convert.toint32(gvdetails.datakeys[e.rowindex].value.tostring()); var productnum = gvdetails.datakeys[e.rowindex].values["productnumber"].tostring(); textbox txtshortdesc = (textbox)gvdetails.rows[e.rowindex].findcontrol("shortdesc"); sqlcommand cmd= sqlhelper.executescalar(globalsettings.dbdsn, commandtype.text,"update sydshortdesc set shortdesc='"+ txtshortdesc.text+ " ' productnumber='"+ productnum +"'  "); cmd.executenonquery(); lblresult.forecolor = color.green; lblresult.text = username + " details updated successfully"; gvdetails.editindex = -1; bindemployeedetails(); } 

well presumably sqlhelper.executescalar method declared return object, not sqlcommand. indeed, wouldn't expect return sqlcommand - i'd expect return results of executing given query. suspect don't want call executescalar in first place.

as very important aside, current code vulnerable sql injection attacks - should use parameterized sql instead of embedding values directly sql.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -