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

    Join Date
    Jul 2003
    Jacksonville, Florida
    Rep Power

    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.

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

    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..

        public bool ftnDataSet_IsColumnExistsQQ(System.Data.DataTable oDataTable, string sColumnName, ref bool bColumnExistQQ)
            string sErrorMsg = "";
                //Parameters' checking...
                //oDataTable = ...
                //sColumnName = ...
                bColumnExistQQ = false;
                //Initialize variables...
                foreach (System.Data.DataColumn oDataColumn in oDataTable.Columns)
                    if (oDataColumn.ColumnName == sColumnName)
                        bColumnExistQQ = true;
                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 10:23 AM.

IMN logo majestic logo threadwatch logo seochat tools logo