ASP.NET Basics (Part 8): Data Overload - Dumped! (Page 3 of 6 ) Now that you're all excited about ADO.NET, lets get our hands dirty with some code, shall we? First, some knowledge of SQL will come in handy over the next few pages. In case you don't know SQL, don't worry - it's extremely simple, and a few minutes with the "Speaking SQL" tutorial at http://www.melonfire.com/community/columns/trog/article.php?id=39 will have you executing queries like an expert. Next, we need some data to play with. For the following examples, I shall be using a Microsoft SQL Server 2000 database called "pubs" and a table named "starwars" containing a list of characters that play vital roles in the epic Star Wars series. Here's the SQL code to create the table (you can use the Query Analyzer tool included with SQL Server 2000 to execute them): CREATE TABLE starwars ( id int IDENTITY (1, 1) NOT NULL , name varchar (50) NULL , homeworld varchar (50) NULL , species varchar (50) NULL , gender varchar (50) NULL , affiliation varchar (50) NULL ) INSERT INTO starwars(name, homeworld, species, gender, affiliation) VALUES('Darth Maul','Iridonia','Zabrak','Male','Sith') INSERT INTO starwars(name, homeworld, species, gender, affiliation) VALUES('Obi-Wan Kenobi','NA','Human','Male','Jedi') INSERT INTO starwars(name, homeworld, species, gender, affiliation) VALUES('Qui-Gon Jinn','NA','Human','Male','Jedi') INSERT INTO starwars(name, homeworld, species, gender, affiliation) VALUES('C-3PO','Tatooine','Droid','NA','Rebel Alliance') INSERT INTO starwars(name, homeworld, species, gender, affiliation) VALUES('Luke Skywalker','Tatooine','Human','Male','Jedi') INSERT INTO starwars(name, homeworld, species, gender, affiliation) VALUES('Darth Vader','Tatooine','Human','Male','Empire')
Once the table has been created, execute the following query in the Query Analyzer to test whether the data has been inserted properly: SELECT * FROM starwars
If you see a list of records, as below, you can be rest assured that the data was inserted properly. With all that out of the way, let's write some code, shall we? Next: Hello Database! >>
More ASP.NET Articles More By Team Melonfire, (c) Melonfire |