Wednesday, April 18, 2007
RSS Reader: Day 5
I finally found a example of Typed DataSets that wasn't all drag and drop and had everything I needed. It's Programming Microsoft ADO.NET 2.0 Core Reference by David Sceppa. His bio in the book says he used to do tech support for Microsoft, supporting Visual Basic and Visual FoxPro. Chapter 9 is devoted entirely to Typed DataSets. After reading part of the chapter, I updated my Pubs test application. Here's the code:
I still have more questions, so Typed DataSet research continues today. For example, why does taAuthors.Update() fail if I call authors.AcceptChanges()?
using System;
using System.Collections.Generic;
using System.Text;
using Pubs.AuthorsTableAdapters;
namespace Pubs
{
class Program
{
static void Main(string[] args)
{
authorsTableAdapter taAuthors = new authorsTableAdapter();
taAuthors.Connection.ConnectionString =
Pubs.Properties.Settings.Default.pubsConnectionString;
// Get all the data and loop through it
Authors.authorsDataTable authors = taAuthors.GetData();
foreach (Authors.authorsRow row in authors)
{
Console.WriteLine("{0} {1}", row.au_fname, row.au_lname);
}
// Add a row
Console.WriteLine("Adding a new row");
Authors.authorsRow newRow = authors.NewauthorsRow();
newRow.au_id = "111-11-1111";
newRow.au_fname = "Joe";
newRow.au_lname = "Tester";
newRow.phone = "555-1212";
newRow.contract = true;
authors.AddauthorsRow(newRow);
//authors.AcceptChanges();
taAuthors.Update(authors);
// Update a row
Console.WriteLine("Updating a row");
Authors.authorsRow editRow = authors.FindByau_id("111-11-1111");
editRow.au_lname = "Examiner";
//authors.AcceptChanges();
taAuthors.Update(authors);
// Delete a row
Console.WriteLine("Deleting a row");
Authors.authorsRow delRow = authors.FindByau_id("111-11-1111");
delRow.Delete();
taAuthors.Update(authors);
Console.WriteLine("Done!");
Console.ReadLine();
}
}
}
Subscribe to Posts [Atom]