none
syntax error in select single statment in sql command RRS feed

  • Question

  • hello all , 

    what is wrong with this code

    it cause an error " incorrect syntax near @title " 

    and i can't figure out the syntax error


     myCom = new SqlCommand("select single ar_news_title , ar_news_details , ar_news_image , ar_news_file into  @title , @details , @image, @file  from ar_news where ar_id =' " + Request.QueryString["id"] + "'", myCon);
            
            P_title = new SqlParameter("@title",SqlDbType.NVarChar,int.MaxValue );
            P_title.Direction = ParameterDirection.Output;
            myCom.Parameters.Add(P_title);
    
             P_details = new SqlParameter("@details",SqlDbType.NVarChar,int.MaxValue );
             P_details.Direction = ParameterDirection.Output;
            myCom.Parameters.Add(P_details);
    
             P_image = new SqlParameter("@image",SqlDbType.VarChar,int.MaxValue );
            P_image.Direction = ParameterDirection.Output;
            myCom.Parameters.Add(P_image);
    
             P_file = new SqlParameter("@file",SqlDbType.NVarChar,int.MaxValue );
            P_file.Direction = ParameterDirection.Output;
            myCom.Parameters.Add(P_file);


    Kareem Naguib

    Wednesday, May 23, 2012 1:15 AM

Answers

  • Hi, 

    About query

    1> There is no "single" keyword available with T-sql. If you are trying to get only record either when query result is ascending or descending you should use

    Select Top 1 [column names] from [table name] order by asc/desc

    2> We cannot have parameter into in single sql query, when the query executed in sql server,  will see @ are not declared and throws exception.

    You can have select query reads the data into DataTable right?  

    select Top 1 ar_news_title , ar_news_details , ar_news_image , ar_news_file from ar_news where ar_id ='@Id'", myCon);
    I hope this helps you...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

    Wednesday, May 23, 2012 3:39 AM