Click here to Skip to main content
15,895,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Button1_Click(object sender, EventArgs e)
        {
           
            Button Button1 = (Button)sender;
            GridViewRow gvRow = (GridViewRow)Button1.NamingContainer;
            FileUpload fuCOA = (FileUpload)gvRow.FindControl("FileUpload1");
            Stream fs = fuCOA.PostedFile.InputStream;
            BinaryReader br = new BinaryReader(fs);
            Byte[] bytes = br.ReadBytes((Int32)fs.Length);
            Label ID = ((Label)gvRow.FindControl("lblApplicantNo"));
            string sql_update = @" update ApplicantData set ApplicantFile=@ApplicantFile";
            sql_update += " where ApplicantNo=@ApplicantNo";
             SqlCommand cmdDist = new SqlCommand(sql_update, con);
            
             cmdDist.Parameters.Add("@ApplicantFile", SqlDbType.Binary).Value = bytes;
             cmdDist.Parameters.AddWithValue("@ApplicantNo", ID.Text.ToString());
                con.Open();
                int i = cmdDist.ExecuteNonQuery();
                con.Close();
                if (i > 0)
                {
                    Response.Redirect("ApplicantExamUpdate.aspx");
                }
           
        }
Posted
Updated 31-Jul-15 21:58pm
v2
Comments
sasanka sekhar panda 1-Aug-15 2:42am    
please specify the line where you get the error..
Ashish Dey 1-Aug-15 3:23am    
Stream fs = fuCOA.PostedFile.InputStream; //error in this line
sasanka sekhar panda 1-Aug-15 3:36am    
check the value of gvRow ,fuCOA in run-time are they null?

1 solution

Use the debugger: The chances are that you spelt "FileUpload1" wrong and it can't find it in this line:
C#
FileUpload fuCOA = (FileUpload)gvRow.FindControl("FileUpload1");

If it isn't that, then it's likely that there is no file available - but you need to use the debugger to find out exactly which part of your statement is null to be sure.
We can't do that for you - we can;t run your code!
 
Share this answer
 

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



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