#1
  1. I lov C in AIX/Linux, hate C++
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jul 2003
    Location
    Jacksonville, Florida
    Posts
    1,655
    Rep Power
    34

    C# error "Cannot apply indexing with [] to an expression of type 'method group'


    The database sometime doesn't contain a field/column name, so I used the if-statement to check for that. I didn't have this problem with VB.NET but in C#, I get a compiler error.

    The compiler error said "Cannot apply indexing with [] to an expression of type 'method group'".

    The blue underline pointed to oDataSet in the if-statement. I'm not sure exactly what the problem is other than I need to add the "()" or "[]" character to object.

    Code:
    if (oDataSet.Tables[0].Columns.Contains["BodyStyle"] == true) 
    {
        this.txtBody.Text = oDataSet.Tables[0].Rows[0]["BodyStyle"].ToString();
    }
    Thanks...

    Edited: It's been a day already and I guess no one know the solution to the problem so I'm leaving this posting open. For now, I came up a temporary workaround to the problem..

    Code:
        public bool ftnDataSet_IsColumnExistsQQ(System.Data.DataTable oDataTable, string sColumnName, ref bool bColumnExistQQ)
        {
            string sErrorMsg = "";
    
            try 
            {
                //Parameters' checking...
                //oDataTable = ...
                //sColumnName = ...
                bColumnExistQQ = false;
    
                //Initialize variables...
    
                foreach (System.Data.DataColumn oDataColumn in oDataTable.Columns)
                {
                    if (oDataColumn.ColumnName == sColumnName)
                    {
                        bColumnExistQQ = true;
                        break;
                    }
                }
    
                return true;
            }
            catch (Exception ex)
            {
                sErrorMsg = ex.Message.ToString(); //To bypass the compiler's warning message...
                //sErrorMsg = System.Reflection.MethodBase.GetCurrentMethod().Name.ToString() + " General Error: Exception - '" + ex.Message.ToString() + "'";
                return false;
            }
        }
    Last edited by fletchsod; September 12th, 2008 at 11:23 AM.

IMN logo majestic logo threadwatch logo seochat tools logo