我在这里有一些错误,我没有问题如何解决它。 它无法调用表的列表
我尝试调用debug,当它到达下面的语句时
List<Int32> ListintNo = DT_ExcludeNo.AsEnumerable().Select(x
=>Convert.ToInt32(x[0].ToString())).ToList();
请帮忙。
DataTable DT_ExcludeNo = new DataTable();
dataAdapter.Fill(DT_ExcludeNo);
InsertLogFile("AMB SP15: Validate Insert Data");
//InsertLogFile("AMB SP15: Execute Query: " + sSqlCommandRetrieveExcludeNO);
List<Int32> ListintNo = DT_ExcludeNo.AsEnumerable().Select(x => Convert.ToInt32(x[0].ToString())).ToList();
for (Int32 i = 1; i <= TotalCount; i++)
{
foreach (Int32 intNo in ListintNo)
{
if (i == intNo)
{
string sSqlCommandRetrieveData = "SELECT Name, [I.C], [D.O.B], NO, [EFF DATE], Sum_Insured from AMB_Temp WHERE NO = " + i;
SqlCommand obj_SQLCommand = new SqlCommand(sSqlCommandRetrieveData, myconn);
dataAdapter = new SqlDataAdapter(obj_SQLCommand);
DataSet DS_RetrieveData = new DataSet();
dataAdapter.Fill(DS_RetrieveData);
//InsertLogFile("AMB SP15: Execute Query: " + sSqlCommandRetrieveData);
DataValidation(DS_RetrieveData);
}
答案 0 :(得分:0)
以下是更新后的代码:
//start new code
string fieldString = x[0].ToString();
if (string.IsNullOrEmpty(fieldString))
{
fieldString = "0";
}
//InsertLogFile("AMB SP15: Execute Query: " + sSqlCommandRetrieveExcludeNO);
List<Int32> ListintNo = DT_ExcludeNo.AsEnumerable().Select(x => Convert.ToInt32(fieldString )).ToList();
//end new code
DataTable DT_ExcludeNo = new DataTable();
dataAdapter.Fill(DT_ExcludeNo);
InsertLogFile("AMB SP15: Validate Insert Data");
//InsertLogFile("AMB SP15: Execute Query: " + sSqlCommandRetrieveExcludeNO);
string fieldString = x[0].ToString();
if (string.IsNullOrEmpty(fieldString))
{ fieldString = "0"; }
List<Int32> ListintNo = DT_ExcludeNo.AsEnumerable().Select(x => Convert.ToInt32(fieldString)).ToList();
for (Int32 i = 1; i <= TotalCount; i++)
{
foreach (Int32 intNo in ListintNo)
{
if (i == intNo)
{
string sSqlCommandRetrieveData = "SELECT Name, [I.C], [D.O.B], NO, [EFF DATE], Sum_Insured from AMB_Temp WHERE NO = " + i;
SqlCommand obj_SQLCommand = new SqlCommand(sSqlCommandRetrieveData, myconn);
dataAdapter = new SqlDataAdapter(obj_SQLCommand);
DataSet DS_RetrieveData = new DataSet();
dataAdapter.Fill(DS_RetrieveData);
//InsertLogFile("AMB SP15: Execute Query: " + sSqlCommandRetrieveData);
DataValidation(DS_RetrieveData);
}
答案 1 :(得分:0)
请检查NO
的数据库列字段数据类型,如果VarChar or Char
您必须更改where语句。
string sSqlCommandRetrieveData = "SELECT Name, [I.C], [D.O.B], NO, [EFF DATE], Sum_Insured from AMB_Temp WHERE NO = " + Convert. ToString(i);