A field or property with the name 'Count' was not found...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

*Help*

I have a collectionbase derived list binding to an ASP.NET
Repeater control (I even added a sort method or two)...

However:
I get this error Message in ASP.NET binding a
collectionbase derived list to a data grid:

A field or property with the name 'Count' was not found on the selected
datasource.

In an windows application binding the same collectionbase
derived list throws this error:

An unhandled exception of type 'System.Reflection.TargetInvocationException'
occurred in system.windows.forms.dll

Additional information: Property accessor 'Count' on object
'SybaseInformation.Entity.SybaseDb' threw the following exception:'Object
does not match target type.'

/* code begin */

using System;
using System.Text;
using System.Collections;

using SybaseInformation.Entity;

namespace SybaseInformation.Lists
{
/// <summary>
/// Summary description for SybaseDbList.
/// </summary>
public class SybaseDbList : CollectionBase
{

#region Constructor

public SybaseDbList() : base()
{
//
// TODO: Add constructor logic here
//
}

#endregion

#region Destructor

~SybaseDbList()
{

List.Clear();

}

#endregion

#region List CollectionBase Specific Routines

public SybaseDbList this[int index]
{

get
{

return (SybaseDbList) List[index];

} // get

set
{

List[index] = value;

} // set

} // public SybaseDbList this[int index])

public int Add(SybaseDb item)
{

SybaseDb obj = new SybaseDb(item);

return List.Add(obj);

} // public int Add(SybaseDb item)

public bool Contains(string sDatabaseName)
{

// this is an not the standard Contains
// as found in CollectionBase

bool bInList = false;

int nWhereAt = 0;

SybaseDb sd = null;

if (List.Count > 0)
{

while ((nWhereAt < List.Count) && (bInList == false))
{

sd = (SybaseDb) List[nWhereAt];

if (sd.DBName == sDatabaseName)
{

bInList = true;

} // if (sd.DBName == sDatabaseName)

nWhereAt++;

} // while ((nWhereAt < List.Count) && (bInList == false))

} // if (List.Count > 0)

return bInList;

} // public bool Contains(string sColumn)

public void CopyTo(SybaseDbList[] array, int index)
{

List.CopyTo(array, index);

} // public void CopyTo(SybaseDbList[] array, int index)

public int IndexOf(SybaseDb item)
{

return List.IndexOf(item);

} // public int IndexOf(SybaseDb item)

public int FindDatabaseName(string sDatabaseName)
{

int nWhereAt = 0;

int nRetVal = -1;

bool bInList = false;

SybaseDb sd = null;

if (List.Count > 0)
{

while ((nWhereAt < List.Count) && (bInList == false))
{

sd = (SybaseDb) List[nWhereAt];

if (sd.DBName == sDatabaseName)
{

bInList = true;

nRetVal = nWhereAt;

} // if (sd.DBName == sDatabaseName)

nWhereAt++;

} // while ((nWhereAt < List.Count) && (bInList == false))

} // if (List.Count > 0)

return nRetVal;

} // public int FindColumn(string sColumn)

public void Insert(int index, SybaseDb item)
{

List.Insert(index, item);

} // public void Insert(int index, SybaseDb item)

public void Remove(SybaseDbList item)
{

List.Remove(item);

} // public void Remove(SybaseDbList item)

public new void RemoveAt(int index)
{

Remove(this[index]);

} // public new void RemoveAt(int index)

public override string ToString()
{

int i = 0;

StringBuilder builder = new StringBuilder(List.Count);

for (i = 0; i < List.Count; i++)
{

builder.Append(List.ToString());

} // for (i = 0; i < List.Count; i++)

return builder.ToString();

} // public override string ToString()

public void Sort(sortDirection sOrder, sortOptions sOptions)
{
IComparer DBNameSorter = new SybaseDbComparer(sOrder,sOptions);
InnerList.Sort(DBNameSorter);
}

#endregion

}
}

/* code end */
 
Have you tried using the class browser to see if Count is actually in
the Sybase collection?

Since you are using Sybase, shouldn't you still be using using
System.Data to create the data table, then you would have something like
this:

// OdbcDataAdapter da = new OdbcDataAdapter(Query, conn);
DataSet ds = new DataSet();
da.Fill(ds);
int count = ds.Tables.Count;

of course the first line is for odbc, and you would have something like
a try catch for the database.

don't know what .Count does in that collection, but I'm guessing it
returns the number of rows.
 
*Hello*
A collectionbase list has an internal List.Count property....

Any other thoughts?
 
Back
Top