May 9, 2007

Using DataTables, DataSets and DataAdaptors

Why use a Dataset? Using summary ADO.NET Tutorial
// Use Visual Studio to generate the data set classes. Use 'Typed' datasets
//XXXDataSet m_XXXDataSet = new XXXDataSet();
// Create the data table and data adaptors
XXXDataSet.XXXDataTable m_XXXDataTable;
XXXDataAdapter m_XXXDataAdaptor = new XXXDataAdapter();

// Filling the dataset/datatable
m_XXXDataTable = m_XXXDataAdaptor.GetData();
//m_DataAdaptor.Fill(m_XXXDataSet.XXX);


//Dont forget to Dispose()
//m_XXXDataSet.Dispose();
m_XXXDataTable.Dispose();
m_XXXDataAdaptor.Dispose();


// Finding a record
//XXXDataSet.XXXRow lir = m_XXXDataSet.XXX.FindByName(requestor.ToLower());
XXXDataSet.XXXRow lir = m_XXXDataTable.FindByName(requestor.ToLower());

// ADD
//m_XXXDataSet.XXX.AddXXXRow(userName, password);
m_XXXDataTable.AddXXXRow(userName, password);
m_Dirty = true;

// DELETE
//m_XXXDataSet.XXX.RemoveXXXRow(lir);
m_XXXDataTable.RemoveXXXRow(lir);
lir.Delete();

// UPDATING the database
m_DataAdaptor.Update(m_XXXDataTable);
//m_DataAdaptor.Update(m_XXXDataSet);

No comments: