Input string was not in a correct format using C# and Oracle -
i'm using oracle , c# download files uploaded.the upload file working fine download function not.i think reason behind it,is passing wrong string format don't know how correct it.i tied usetryparse
didn't work because think didn't use maybe.please me sort out issue. thank you
error line :
int resources_id = convert.toint32(gvdetails.datakeys[gvrow.rowindex].value.tostring());
stack trace:
[formatexception: input string not in correct format.] system.number.stringtonumber(string str, numberstyles options, numberbuffer& number, numberformatinfo info, boolean parsedecimal) +10689507 system.number.parseint32(string s, numberstyles style, numberformatinfo info) +145 system.convert.toint32(string value) +43 lecturer_upload_resources.lnkdownload_click(object sender, eventargs e) in c:\users\aa551\dropbox\website4\lecturer\upload resources.aspx.cs:67 system.web.ui.webcontrols.linkbutton.onclick(eventargs e) +116 system.web.ui.webcontrols.linkbutton.raisepostbackevent(string eventargument) +101 system.web.ui.webcontrols.linkbutton.system.web.ui.ipostbackeventhandler.raisepostbackevent(string eventargument) +10 system.web.ui.page.raisepostbackevent(ipostbackeventhandler sourcecontrol, string eventargument) +13 system.web.ui.page.raisepostbackevent(namevaluecollection postdata) +9643314 system.web.ui.page.processrequestmain(boolean includestagesbeforeasyncpoint, boolean includestagesafterasyncpoint) +1724
my code :
using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using system.data.oracleclient; using system.configuration; using system.io; public partial class lecturer_upload_resources : system.web.ui.page { string strcon = "data source=****;persist security info=true;user id=****;password=****;unicode=false"; protected void page_load(object sender, eventargs e) { if (!ispostback) { bindgridviewdata(); } } // bind gridview data private void bindgridviewdata() { using (oracleconnection con = new oracleconnection(strcon)) { using (oraclecommand cmd = new oraclecommand()) { cmd.commandtext = "select * resource1"; cmd.connection = con; con.open(); gvdetails.datasource = cmd.executereader(); gvdetails.databind(); con.close(); } } } // save files folder , files path in database protected void btnupload_click(object sender, eventargs e) { string filename = path.getfilename(fileupload1.postedfile.filename); stream str = fileupload1.postedfile.inputstream; binaryreader br = new binaryreader(str); byte[] size = br.readbytes((int)str.length); using (oracleconnection con = new oracleconnection(strcon)) { using (oraclecommand cmd = new oraclecommand()) { cmd.commandtext = "insert resource1(filename,filetype,filedata) values(:filename,:filetype,:filedata)"; cmd.parameters.addwithvalue(":filename", filename); cmd.parameters.addwithvalue(":filetype", "application/word"); cmd.parameters.addwithvalue(":filedata", size); cmd.connection = con; con.open(); cmd.executenonquery(); con.close(); bindgridviewdata(); } } } // button click event used download files gridview protected void lnkdownload_click(object sender, eventargs e) { linkbutton lnkbtn = sender linkbutton; gridviewrow gvrow = lnkbtn.namingcontainer gridviewrow; int resources_id = convert.toint32(gvdetails.datakeys[gvrow.rowindex].value.tostring()); string filename, filetype; using (oracleconnection con = new oracleconnection(strcon)) { using (oraclecommand cmd = new oraclecommand()) { cmd.commandtext = "select filename, filetype, filedata resource1 resources_id=:resources_id"; cmd.parameters.addwithvalue(":resources_id", resources_id); cmd.connection = con; con.open(); oracledatareader dr = cmd.executereader(); if (dr.read()) { response.contenttype = dr["filetype"].tostring(); response.addheader("content-disposition", "attachment;filename=\"" + dr["filename"] + "\""); response.binarywrite((byte[])dr["filetype"]); response.end(); } } } } protected void gvdetails_selectedindexchanged(object sender, eventargs e) { } }
Comments
Post a Comment