Web Log di Adrian Florea

"You know you've achieved perfection in design, not when you have nothing more to add, but when you have nothing more to take away." Antoine de Saint-Exupery
posts - 440, comments - 2715, trackbacks - 3944

My Links

Archives

Post Categories

Image Galleries

.RO Blogs

.RO People

.RO Sites

Blogs

Furls

Links

vinCitori

Dal Recordset al DataSet

Per trasformare un DataSet in un Recordset hanno parlato nei loro libri Dino Esposito (vedi "Programmare XML in Microsoft .NET", pp. 170-179 e pp. 326-332) e Paolo Pialorsi con Marco Russo (vedi ".NET XML & WebServices Full Contact", pp. 27-35).

Magari pochi sanno la strada contraria: quella dal Recordset al DataSet. Per loro il seguente snippet:

public sealed class AdoConvert
{
  private AdoConvert(){}

  public static DataSet ToDataSet(ADODB.Recordset rs)
  {
    OleDbDataAdapter da = new OleDbDataAdapter();
    DataTable dt = new DataTable();
    DataSet ds = new DataSet();

    da.Fill(dt, rs);
    ds.Tables.Add(dt);

    return ds;
  }

  public static DataSet ToDataSet(string recordsetXml)
  {
    ADODB.Recordset rs = new ADODB.Recordset();
    ADODB.Stream stream = new ADODB.Stream();
    DataSet ds = new DataSet();

    stream.Open(Missing.Value, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", "");
    stream.WriteText(recordsetXml, ADODB.StreamWriteEnum.stWriteChar);
    stream.Position = 0;
    rs.Open(stream, Missing.Value, ADODB.CursorTypeEnum.adOpenUnspecified, ADODB.LockTypeEnum.adLockUnspecified, -1);

    ds = ToDataSet(rs);

    rs.Close();
    stream.Close();

    return ds;
  }
}

in cui si deve referenziare la dll "adodb.dll" che si trova in "C:\Program Files\Microsoft.NET\Primary Interop Assemblies".

La canzone del giorno: Chemical Brothers - "Let Forever Be".

Print | posted on sabato 16 ottobre 2004 21:46 | Filed Under [ Carillon .NET ]

Powered by:
Powered By Subtext Powered By ASP.NET