2016-04-18 77 views
0

我想用SQL數據庫中的數據填充PDF上的某些字段,我有一個數據訪問類,但無法獲得行中的值:使用DataTable填充行與存儲過程中的數據

DataAccess DA = new DataAccess(); 

DataSet S = DA.CashData(); 

DataTable Cash = S.Tables[0]; 
DataTable Other = S.Tables[1]; 
DataTable Check = S.Tables[2]; 
DataTable Else = S.Tables[3]; 

string s = ""; 

foreach (DataRow row in Cash.Rows) 
{ 
    foreach (DataColumn col in Cash.Columns) 
    { 
     for (int i = 0; i < Cash.Columns.Count; i++) 
     { 
      DataRow cashRow = Cash.Rows[i]; 
      s = s + cashRow[0].ToString() + ";"; 
     } 
    } 

    Console.ReadLine(); 
} 

string[] data = s.Split(';'); 
cell32.AddElement(new Paragraph("")); 
cell32.AddElement(new Paragraph(data[0])); 
cell32.AddElement(new Paragraph(data[1])); 

列顯示的數據,但該行不

回答

1

如果我正確理解你的源,你必須在你的循環對行的錯誤執行,請考慮此編輯來源:

DataAccess DA = new DataAccess(); 
DataSet S = DA.CashData(); 
DataTable Cash = S.Tables[0]; 
DataTable Other = S.Tables[1]; 
DataTable Check = S.Tables[2]; 
DataTable Else = S.Tables[3]; 
string s = ""; 

foreach (DataRow row in Cash.Rows) 
{ 
    for (int i = 0; i < row.Columns.Count; i++) 
    { 
     s += row[0].ToString() + ";"; 
    } 
    Console.ReadLine(); 
} 

string[] data = s.Split(';'); 
cell32.AddElement(new Paragraph("")); 
cell32.AddElement(new Paragraph(data[0])); 
cell32.AddElement(new Paragraph(data[1])); 
+0

嗨,喬姆斯克1e 將行[0] .ToString中的0更改爲行[i] .Tostring似乎已經做到了!非常感謝你 – Nonagon

相關問題