Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I'm getting the above error while trying to get the image from the table.

Here is my code

protected void Page_Load(object sender, EventArgs e)
   {
       string id = Request.QueryString["id"].ToString();

       SqlCommand cmd = new SqlCommand("select photoName from registration where Id='" +id + "'", con);
       con.Open();
       SqlDataReader rdr = cmd.ExecuteReader();
       while (rdr.Read())
           {
               byte[] byteArr = (byte[])rdr["PhotoName"];
               Response.BinaryWrite(byteArr);

           }

       rdr.Close();
       con.Close();
   }


Getting error near
<b>   byte[] byteArr = (byte[])rdr["PhotoName"];</b>
while Executing the code .

Please help me solve this.

Thanks in Advance.
Posted
Updated 10-Mar-14 19:00pm
v2
Comments
Aravindba 11-Mar-14 1:09am    
PhotoName is name or binary in table ? r u going to convert string to bytes ?
[no name] 11-Mar-14 1:11am    
Photoname is the name of field
[no name] 11-Mar-14 1:11am    
no no actually i have stored images in table in binary format.

1 solution

Hi pls check ur field,PhotoName is string or binary in the fields.

try like this

C#
byte[] byteArr = ((byte[])rdr["PhotoName"]);
 
Share this answer
 
v2
Comments
[no name] 11-Mar-14 1:17am    
It is binary only
Aravindba 11-Mar-14 1:20am    
try updated solution
[no name] 11-Mar-14 1:23am    
ok ok

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