Erm...Can you seriously not see the problem here? If not, I suspect you should go back to basics and learn to program properly instead of guessing... The following should be obvious:
Your method is declared as returning a
List
(
public List getall()
) yet you are returning a string (
return db.banks.ToString()
). This is not only impossible (hence your error) but also complete nonsense code! Your return type is different from what you are trying to return! Also,
ToString
on the database's
banks
table will just return you a string (piece of text) telling you the C# type is a DataTable - it won't return you a massive string with all the records in it!
What were you trying to do? Return all the records from that database table? A somewhat questionable operation (since if the table is very big it could take a very long time to complete) but the code you probably want is:
public List<bank> GetAll()
{
return db.banks.ToList();
}
</bank>
Note: Method declaration now includes
List<bank>
. The word "bank" is the name of the type contained within your list. I have assumed (from your table name "banks") that the C# type (that is auto-generated by C# for you) that represents the data table types is called "bank".
Hope this helps,
Ed
P.s. If you still don't get it / have errors, I suggest you go back, learn how methods and types work (read MSDN) then search Google/MSDN/CodeProject for how to use
Lists
and how to use the database classes properly. Ideally you would be using an
IQueryable
not a
List
.