21 August 2007

ADO.NET On the Brain

by mo

Good Morning! Well I’m feeling a little sluggish this morning. It’s always tough going straight to sleep on school nights. You just feel a little cheated when you get home, because I want to squeeze a little bit of time out of the evening for myself. Not to mention my brain was just buzzing in bed, and it took a little longer to wind down then usual.

In the last couple of days I have been reading through Jeremy Miller’s articles on how to build your own CAB. It’s definitely worth a read, I’ve learned a lot so far.

On Sunday, I just about wrapped up an assignment for class. It’s focus is on ADO.NET and data access… I’m hoping I’ll be able to publish my work after the due date but in the mean time here’s a sample…

To select data I build a SelectQueryBuilder object that can be used like this…

  public IEnumerable<IDropDownListItem> GetAllVendorNames() 
    SelectQueryBuilder builder = new SelectQueryBuilder(Tables.Vendors.TableName);
    return CreateItemsFrom(_gateway.GetTableFrom(builder));

To update a row in the database you would use my home brewed UpdateQueryBuilder.

  public void UpdateInvoice(UpdateInvoiceDto dto) 
    UpdateQueryBuilder builder = new UpdateQueryBuilder(Tables.Invoices.InvoiceID, dto.InvoiceId);
    builder.Add(Tables.Invoices.CreditTotal, dto.CreditTotal);
    builder.Add(Tables.Invoices.DueDate, dto.DueDate);
    builder.Add(Tables.Invoices.InvoiceDate, dto.InvoiceDate);
    builder.Add(Tables.Invoices.InvoiceNumber, dto.InvoiceNumber);
    builder.Add(Tables.Invoices.InvoiceTotal, dto.InvoiceTotal);
    builder.Add(Tables.Invoices.PaymentDate, dto.PaymentDate);
    builder.Add(Tables.Invoices.PaymentTotal, dto.PaymentTotal);
    builder.Add(Tables.Invoices.TermsID, dto.TermsId);


One of the coolest things I Found in ADO.NET 2.0 was DbProviderFactories. There’s so much good stuff that was introduced in 2.0 that I know I wasn’t taking advantage of.

csharp database