Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
I have error in this Code i can't Find it
 
Error in this line 4 (string query = "if exists(select Avatar from pets Where Skey = @Skey);)
 
           string connectionString = WebConfigurationManager.ConnectionStrings["conString"].ConnectionString;
           SqlConnection con = new SqlConnection(connectionString);
           string query = "if exists(select Avatar from pets  Where Skey = @Skey);
           query += " begin select Avatar from pets  Where Skey = @Skey end";
           query += " else  begin select Avatar from pets  Where Skey = '1' end" ;
           SqlCommand cmd = new SqlCommand(query, con);
           con.Open();
           cmd.Parameters.AddWithValue("@Skey", Request.QueryString["ID"]);
           object ReturnImage = cmd.ExecuteScalar();
           byte[] photo = (byte[])ReturnImage;
           Response.BinaryWrite(photo);
           con.Close();
Posted 28-Mar-13 23:54pm
Edited 29-Mar-13 0:05am
phil.o35.7K
v3
Comments
Sandeep Mewara at 29-Mar-13 5:17am
   
Please share 'exact full error' and also what are you trying to do?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Pretty clear : you forgot to close the quote at the end of line (before semicolon).
Thought it was a typo on your post ; but it appears it's the real problem.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Corrected your code..
 
 string connectionString = WebConfigurationManager.ConnectionStrings["conString"].ConnectionString;
           SqlConnection con = new SqlConnection(connectionString);
           string query = "if ((select COUNT(Avatar) from pets  Where Skey = @Skey)> 0)";
           query += " begin select Avatar from pets  Where Skey = @Skey end";
           query += " else  begin select Avatar from pets  Where Skey = '1' end" ;
           SqlCommand cmd = new SqlCommand(query, con);
           con.Open();
           cmd.Parameters.AddWithValue("@Skey", Request.QueryString["ID"]);
           object ReturnImage = cmd.ExecuteScalar();
           byte[] photo = (byte[])ReturnImage;
           Response.BinaryWrite(photo);
           con.Close();
 
And one more thing-----------
 
Where Skey = '1' end" ;
 
should be
 
Where Skey = 1 end" ;
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 539
1 Maciej Los 300
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 29 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100