Hi Ryan0007,
为了确认是不是DataTable相关的代码有问题, 我建议你添加一个新的方法,这个方法只返回一个简单的String, 比如“Hello World”. 如果结果显示只有返回DataTable的方法出错,我建议你把GetClientList这个方法里的代码分享给我们看下。
我对于 DataTable做了下面的测试,是没有问题的。
Service
public DataTable GetTable()
{
MakeParentTable();
DataTable dt = dataSet.Tables[0];
return dt;
}
private System.Data.DataSet dataSet;
private void MakeParentTable()
{
// Create a new DataTable.
System.Data.DataTable table = new DataTable("ParentTable");
// Declare variables for DataColumn and DataRow objects.
DataColumn column;
DataRow row;
// Create new DataColumn, set DataType,
// ColumnName and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "id";
// Add the Column to the DataColumnCollection.
table.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "ParentItem";
// Add the column to the table.
table.Columns.Add(column);
// Instantiate the DataSet variable.
dataSet = new DataSet();
// Add the new DataTable to the DataSet.
dataSet.Tables.Add(table);
// Create three new DataRow objects and add
// them to the DataTable
for (int i = 0; i <= 2; i++)
{
row = table.NewRow();
row["id"] = i;
row["ParentItem"] = "ParentItem " + i;
table.Rows.Add(row);
}
}
Client
DbOperationService.DbOperationClient client = new DbOperationService.DbOperationClient();
DataTable dt = client.GetTable();
MessageBox.Show(dt.Rows.Count.ToString());
我建议你测试下上面的代码,看下是否跟你创建的DataTable有关系。
Best Regards,
Edward
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.