ublic DataTable PickoutFromDataTable(DataTable objDataTable,string fromCity,string toCity)
{
int count = objDataTable.Rows.Count;
//逐个读出车次进行判断
for(int i = 0;i <count; i++)
{
DataRow row = objDataTable.Rows[i];
string trainCode = row[0].ToString();
//theOrder列为经过的站次,已按从小到大编号
string strSqlStatement = "select trainCode from trainCodeDetails where trainCode = '"+trainCode+"' and berthCity = '"+fromCity+"' and theOrder < (select theOrder from trainCodeDetails where trainCode = '"+trainCode+"' and berthCity = '"+toCity+"')";
if(CheckStationOrder(strSqlStatement))
{
objDataTable.Rows[i].Delete();
}
}
objDataTable.AcceptChanges();
return objDataTable;
}
//根据返回的行数判断是否符合条件
public bool CheckStationOrder(string strSqlStatement)
{
bool result = false;
//CreateDataTable方法的功能是:根据提供的sql语句返回一个DataTable对象
DataTable objDataTable = objDbOperation.CreateDataTable(strSqlStatement);
if(objDataTable.Rows.Count == 0 )
{
result = true;
}
return result;
}
//程序实现的功能是:根据用户输入的起点站与终点站查询 经过两站之间的列车。首先查出经过这两个站之间的所有列车(没有区分起始站顺序),然后再调用PickoutFromDataTable进行筛选。如果返回的行数不为空,证明此列车符合从始发站至终点站的先后顺序,否则就将相应的DataRow删除。
//问题是:查询就出错,错误信息:"在位置1处没有任何行。"(在红色部分)
//请问如何解决。小弟感激不尽!