Link to home
Start Free TrialLog in
Avatar of ube100
ube100Flag for United Kingdom of Great Britain and Northern Ireland

asked on

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.
Avatar of anv
anv

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]
ASKER CERTIFIED SOLUTION
Avatar of openshac
openshac

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial