Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);)

C#
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
Updated 28-Mar-13 23:05pm
v3
Comments
Sandeep Mewara 29-Mar-13 5:17am    
Please share 'exact full error' and also what are you trying to do?

Corrected your code..

SQL
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" ;
 
Share this answer
 
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.
 
Share this answer
 
v2

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