Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 579
  • Last Modified:

datatable

Hi,
My VB application is producing this recordset object:

 Set RecAvailability = CreateObject("ADOR.Recordset")
   
    With RecAvailability.fields
            Call .Append("StartDate", adBSTR, , adFldIsNullable)
            Call .Append("Duration", adBSTR, , adFldIsNullable)
    End With
   
    RecAvailability.open
   
    With RecAvailability
            .AddNew
            .fields("StartDate").Value = Format(dteStartDate, "yyyy-mm-dd")
            .fields("Duration").Value = GetDurationCode(intDuration)
        .UpdateBatch
    End With
   
    'Create the recordset for the room hotel reference.
   
    Set RecHotel = New ADOR.Recordset
   
    With RecHotel.fields
            Call .Append("HotelRef", adBSTR, , adFldIsNullable)
    End With
   
    RecHotel.open
   
    With RecHotel
        For i = 0 To moRecRooms.RecordCount - 1
            .AddNew
            .fields("HotelRef").Value = strItemCode
        Next i
        .UpdateBatch
    End With

Once it done that it calling a .net function:
Call tmsGDS.AddRecordset(RecAvailability, "Availability")
 Call tmsGDS.AddRecordset(RecHotel, "Hotel")

And the .net functions are:

public bool AddRecordset(ADOR.Recordset rs, string name)
            {
                  // Convert the recordset to a dataset
                  OleDbDataAdapter myDA = new OleDbDataAdapter();
                  DataTable myDT = new DataTable(name);
                  myDA.Fill(DS, rs, name);
                  bool ret = AddDataTable(myDT, name);
                  return ret;
            }

public bool AddDataTable(DataTable dt, string name)
            {
                  if (DS.Tables[name] == null)
                  {
                        DS.Tables.Add(dt);
                  }
                  else
                  {
//                        DataRow dr;
//                        dr = DS.Tables[name].NewRow();
//                        dr[0] = DS.Tables[name].Rows[0].ToString();
//                        DS.Tables[name].Rows.Add(dr);
                  }

Since the VB producing single value as a recordset in turn each recordset is created as a datatable in the .net. But the trouble is the way this .net function is implemented it cannot take any more than one value for a repeating row as it will ignore that row because that table name already exists in the dataset. AS you can see from the "AddDataTable" function else claues I have commented out should be handling this scenario but that's not doing that at the moment. Can somebody show me how can I achieve this please.
0
ube100
Asked:
ube100
1 Solution
 
anvCommented:
dont understand what you are doing here:

from AddRecordset you are calling: myDA.Fill(DS, rs, name);
                  bool ret = AddDataTable(myDT, name);
instead you should pass DS to AddDataTable
in AddDataTable you should then use DS.Tables[name]
0
 
openshacCommented:
You cannot add DataRows from one DataTable to another, you have to Import them using the ImportRow() method
DataRow dr;
dr = DS.Tables[name].NewRow();
dr[0] = DS.Tables[name].Rows[0].ToString();
//DS.Tables[name].Rows.Add(dr);
DS.Tables[name].ImportRow(dr);

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now