Need simple help
I have two data table. I have method which copying data columns from dt data table to dtHelper table like this:
foreach (DataColumn col in dt.Columns)
{
string colname = col.ColumnName.ToString();
dtHelper.Columns.Add("" + colname + "", dt.Columns["" + col + ""].DataType);
}
This method receiving three values int CheckInID,string _ServiceName and _ServicePrice than adding new column which columName is servicename than copying rows from dt to dthelper and adding serviceName column serviceprice where ID = CheckInID
this is how:
ArrayList arr = ConvertDT(ref dt);
foreach (Object obj in arr)
{
string _ID = ((DataRow)obj)["ID"].ToString();
string _RoomType = ((DataRow)obj)["Room Type"].ToString();
string _RoomNumber = ((DataRow)obj)["Room"].ToString();
string _RoomPrice = ((DataRow)obj)["Room Price"].ToString();
string _Discount = ((DataRow)obj)["Discount"].ToString();
string _DiscountedPrice = ((DataRow)obj)["Discounted Price"].ToString();
string _CheckInDate = ((DataRow)obj)["Check In Date"].ToString();
string _CheckOutDate = ((DataRow)obj)["Check Out Date"].ToString();
string _TotalDays = ((DataRow)obj)["Total Days"].ToString();
string _TotalPrice = ((DataRow)obj)["Total Price"].ToString();
Boolean _IncFirstDay = Convert.ToBoolean(((DataRow)obj)["Inc. First Day"]);
string _PaidMoney = ((DataRow)obj)["Paid Money"].ToString();
if (Convert.ToInt32(_ID) == CheckInID)
{
_ServiceName = ServiceName;
dtHelper.Rows.Add(
_ID,
_RoomType,
_RoomNumber,
_RoomPrice,
_Discount,
_DiscountedPrice,
_CheckInDate,
_CheckOutDate,
_TotalDays,
_TotalPrice,
_IncFirstDay,
_PaidMoney,
_ServicePrice);
}
else
{
dtHelper.Rows.Add(
_ID,
_RoomType,
_RoomNumber,
_RoomPrice,
_Discount,
_DiscountedPrice,
_CheckInDate,
_CheckOutDate,
_TotalDays,
_TotalPrice,
_IncFirstDay,
_PaidMoney,
_ServicePrice);
}
_ServicePrice = "";
So this works very well but the problem is that when I second service it, adding in first servicename column, I don't know in advance how much services would be (user adding it with window).
How can I modify _dtHelper.Rows.Add?
For example if I added service (which name is skis serv) and in table create a new column, then I added price below that column and along for example 25 ID row.
I want to add second service(restaurant service) on ID 27 it would be something like that : enter image description here and it must be like this
http://imageshack.us/photo/my-images/32/2222im.png/[
^]
http://imageshack.us/photo/my-images/855/firstal.png/[
^]