Click here to Skip to main content
11,709,844 members (49,925 online)
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 22:54pm
Edited 28-Mar-13 23:05pm
phil.o51.6K
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 Sergey Alexandrovich Kryukov 524
1 OriginalGriff 250
2 Peter Leow 229
3 Maciej Los 185
4 Mika Wendelius 160
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,037
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 29 Mar 2013
Copyright © CodeProject, 1999-2015
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