locked
Select statement gives me error RRS feed

  • Question

  • The Select statement gives me error if using the single quotation mark in string.

                DataTable dtColor = new DataTable();

                dtColor.Columns.Add("Colors");

                dtColor.Rows.Add("Red's");

                dtColor.Rows.Add("Green");

                dtColor.Rows.Add("Blue");

                string strColor = "Red's";

                DataRow[] Colors = dtColor.Select("Colors='" + strColor + "'");

    Gives error as follows :

                Syntax error: Missing operand after 's' operator.


    Thursday, July 22, 2010 10:04 AM

Answers

  • DataTable dtColor = new DataTable();
          dtColor.Columns.Add("Colors");
          dtColor.Rows.Add("Red's");
          dtColor.Rows.Add("Green");
          dtColor.Rows.Add("Blue");
          string strColor = "Red's";
          DataRow[] Colors = dtColor.Select("Colors = '" + strColor.Replace("'","''") + "'");
    

    Nanda - Misys Software Solutions,Bangalore
    • Marked as answer by Neorman Thursday, July 22, 2010 12:28 PM
    Thursday, July 22, 2010 10:19 AM