manoj naga

manoj naga

  • NA
  • 5
  • 6.4k

exception in sql query

Mar 21 2013 7:47 AM
Hi 
i have the below code to extract details from table  between two dates but it is raising an exception saying wrong syntax near FROM clause 

please suggest the correct solution

(string FromDate,string ToDate)

    {

        OleDbConnection xlConn = new OleDbConnection(ConnectionString);

 

        using (xlConn)

        {

            OleDbDataAdapter dAd = new OleDbDataAdapter(@"SELECT tbC.ContID , tbC.Posted_User,

            tbC.Content, tbC.PostedDate,  tbG.Catg_Name ,tbP.PU_Name FROM

((tblAllContent tbC INNER JOIN tblCatg tbG ON tbC.Catg_ID = tbG.CID)

            INNER JOIN tblPU tbP ON tbC.PU_ID = tbP.PID) AND tbc.PostedDate BETWEEN "+FromDate + "AND "+ToDate , xlConn);

            DataTable dt = new DataTable();

            try

            {

                xlConn.Open();

                dAd.Fill(dt);

                return dt;

            }

            catch (Exception ex)

            {

                return null;

            }

            finally

            {

                xlConn.Close();

                xlConn.Dispose();

 

            }

        }

    }

}

 


Answers (1)