Psuedo code for ADO .NET procedure

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've ordered Bill Vaughn's book, which I hope will help me with this, but in the meantime, can someone point me to an RTFM or give me some outline of how to attack this problem? I've read the docs and even a book on ADO .NET, so I'm familiar in general with all the components (DataAdapters, DataReaders, DataSets, DataTables, etc.)

I'd simply like to display all athletes in a specific grade joined to a table that shows their sport (table defs and query below). I'd like this to be in a grid that the user can edit to change athlete information, then update the database. I don't care if the solution is manual or disconnected, or whatever... I just need to get started with this stuff to better understand it.

CREATE TABLE ATHLETE (ATHLETE_ID INT NOT NULL, SPORT_ID INT NOT NULL, LNAME VARCHAR(100), FNAME VARCHAR(50))

CREATE TABLE SPORT (SPORT_ID INT NOT NULL, SPORT_NAME VARCHAR(100), MAX_PARTICIPANTS INT)

SELECT LNAME, FNAME, SPORT_NAME
FROM ATHLETE, SPORT
WHERE ATHLETE.SPORT_ID = SPORT.SPORT_ID

Simple example, but it will get me moving.

Thanks,

billy
 
The problem with your scenario (as simple as it is), is that the DataAdapter etal. are designed to work with a single table. Your SELECT joins two tables so you need to create a separate DataAdapter for each table so they can be updated individually--and (possibly) a third DataAdapter to return the JOIN rowset. If you don't plan to change both tables, you can get away with a single DataAdapter--but you'll have to fill in the SqlCommands by hand. This seems like a lot of trouble and some choose not to take this approach. What some folks do (and I illustrate in the book) is create a single SELECT (as you have done) and use it to populate the DataGrid. I then create stored procedures that do the Update, Insert and Delete operations. Remember the Update method simply walks the DataTable and executes the appropriate SqlCommand for each operation that's needed--while it maps the current table columns to the command parameters, it does not care what these commands do as long as they command returns rows affected = 1.

hth



--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Back
Top