1
我有大小像3,6,9,12,15-返回數據的數組。(3乘法)我們怎樣才能從數組文本篩選
DataTable dt = new DataTable();
string GridData = ViewState["ShowItem"].ToString();
string[] FilterData = GridData.Split('^');
以上陣列返回的數據像..
FilterData [0] = "Pizza"; (Item)
FilterData [1] = "2$"; (Price)
FilterData [2] = "2"; (Quantity)
FilterData [3] = "Burger";
FilterData [4] = "5$";
FilterData [5] = "1";
FilterData [6] = "Cesa";
FilterData [7] = "7$";
FilterData [8] = "3";
now I want to enter above data as column wise in database like:
Item Price Quantity Total(Price*Quantity)
現在我想運行一個循環,增加特定領域的數據,如:
for (int nIndex = 0; nIndex < FilterData.Length; nIndex++)
{
DataRow drow = dt.NewRow();
drow["ProductItem"] = FilterData[nIndex].ToString(); (Add all Item)
drow["Cost"] = FilterData[nIndex].ToString(); (Add all Cost)
drow["Quantity"] = FilterData[nIndex].ToString(); (Add all Quantity)
double Total= Convert.ToDouble(FilterData[nIndex].ToString()) * Convert.ToInt32(FilterData[nIndex].ToString()); (Add all cost*Quantity)
drow["Total"] = Total;
dt.Rows.Add(drow);
}
所以任何人可以幫助我,我怎麼能運行循環,因此數據添加到特定的列,如: 項目價格數量合計(價格*數量)
Pizza 2 2 4
Burger 5 1 5
Cesa 7 3 21
精彩親愛的!它工作正常。非常感謝短邏輯&它減少了我的行代碼數量。謝謝:) – Steve
智能答案p.s.w.g! – Steve
@Steve很高興幫助。快樂編碼:) –