Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm using oracle and C# to download files that I uploaded.The upload file is working fine but the download function is not.I think the reason behind it,is passing the wrong string format but I don't know how to correct it.I tied to usetryparse but didn't work because I think I didn't use it well maybe.Please help me sort out this issue. Thank you

Error line :
int Resources_id = Convert.ToInt32(gvDetails.DataKeys[gvrow.RowIndex].Value.ToString());

    // This button click event is used to download files from gridview
     protected void lnkDownload_Click(object sender, EventArgs e)
    {
        LinkButton lnkbtn = sender as LinkButton;
        GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
        Object o = gvDetails.DataKeys[gvrow.RowIndex].Value;
        if (o != DBNull.Value)
        {                      
    }

}
Posted
Updated 8-Apr-14 18:46pm
v3
Comments
CHill60 10-Mar-14 12:46pm    
If you step through with the debugger what are the contents of gvDetails.DataKeys[gvrow.RowIndex].Value?
aa00101 10-Mar-14 12:57pm    
the value of it is {} and type is object {System.DBNull},thats what I found when I run the debugger .
and for gvDetails.DataKeys its value is {System.Web.UI.WebControls.DataKeyArray}

1 solution

the value of it is {}  and type is object {System.DBNull},thats what I found when I run the debugger .
and for gvDetails.DataKeys its value is {System.Web.UI.WebControls.DataKeyArray}


DBNull cannot be converted to an integer - it is a specific value that indicates that the DB column has no value. Hence, none of the conversion methods can change it to a number!
Instead, check the column value before you try:
C#
object o = gvDetails.DataKeys[gvrow.RowIndex].Value
if (o != DBNull.Value)
   {
   int Resources_id = Convert.ToInt32(o);
   string filename, filetype;
   using (OracleConnection con = new OracleConnection(strCon))
      {
      ...
You may want to include an else which reports a problem - but that's up to you.
 
Share this answer
 
Comments
aa00101 10-Mar-14 13:36pm    
Thank you for your help. I did change the code as you said,it doesn't give me any error but it doesn't function or respond to anything. You can see in the page I updated the code.Thx
OriginalGriff 10-Mar-14 13:55pm    
That's kind of the idea!
If the data you are working with is null, then it's up to you to decide what to do: hence my comment about the "else"condition.
You probably need to look at *why* you are getting a null value - which means you looking at your data.
aa00101 10-Mar-14 14:17pm    
I think it should not respond only if i don't have anydata inside to download, but I already upload files but download function doesn't take it.and about the ELSE it should be Console.WriteLine (""); then put the expeption when it is not null? .I'm sorry as i'm just a beginner . thx
OriginalGriff 10-Mar-14 15:08pm    
If you are getting nothing at all, then it implies that all of them are null.
So start by using the else to gather information (Console.WriteLine is fine, or use the debugger), or look at your data. I can't - I don't have any access to it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900