I have a data adapter with a method that that takes a variable and returns all entries that matches the variable:

e.g.

TableAdaptor ta = new TableAdaptor();
DataTable dt = ta.GetUserByUserID(UserID);

But I can't for the life of me figure out how to return a single cell value from the method. Since it's a strongly typed datatable, the column name becomes a property of the datatable so I can do:

dt.UserIDColumn.ToString();

But this returns the name of the column and not the value of the cell. And if I try:

dt.Rows[0]

there is no column property according to VS10's intellisense. What am I missing here?

有帮助吗?

解决方案

OK, I'm assuming you're not really declaring a variable of type DataTable to hold your strongly typed data table, because as the base class, that won't have all the strongly typed columns, etc.

Try this:

StronglyTypedDataTable dt = ta.GetUserByUserID(UserID);   
StronglyTypedRow row = dt[0];
var value = row.ColumnName;

If memory serves, the strongly typed table will be indexable, and you'll be able to access strongly typed data rows. Those will have strongly typed properties representing the individual cells, by name.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top