13.07.2015 Views

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

296<strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong>: A Beginner’s <strong>Guide</strong>That SQL query is the sequence you would use in a C# statement to make a databasequery to the Supporters table.6. Finally, place the mouse anywhere on the Query editor and right-click it. Select ExecuteQuery. At the bottom panel, you should see the output from your table as shown inFigure 12-9.At this point you have a database, a table, and data with which to practice queries. Usingthe <strong>com</strong>mands from Chapter 11, you should be able to use this to practice SQL queries. Youmight want to take a look at a good introduction to databases if you’re not familiar withthem. Databases Demystified by Andrew Oppel (McGraw-Hill, 2004) is a good jumping-offpoint. The next step is to get these <strong>com</strong>mands arranged in a web site for real-world use.Creating Web Sites for Database UseNow that the table in the database is ready for use, we need to examine how to use <strong>ASP</strong>.<strong>NET</strong>and C# to work with ADO.<strong>NET</strong> in an application. Using a SQL server, you will find that thekey SQL <strong>com</strong>mands begin with—what else?—Sql. In this section we will examine what youneed to connect to a database, to make a query, and to output the data to the screen.NOTEIf you are working with Microsoft Access or with an Oracle database, you can use anOdbcConnection (Oracle) or OleDbConnection (Access) connection. Those mustbe set up by importing the System.Data.Odbc (Oracle) or System.Data.OleDb(Access) namespaces. Everything works very much like the SqlConnection as far asconnecting to the database is concerned.First Use the SqlClient NamespaceWhen you’re ready to launch your database application, the first thing you need to rememberis to import the SqlClient namespace. You set it up as a property of System.Dataas follows:using System.Data.SqlClient;It’s easy to forget, but in this section and the remainder of the chapter, you’ll be using itfor all of the different Sql... <strong>com</strong>mands that you need to use.TIPThe process in setting up a database is a one-time operation. Because of that, you’reapt to forget the name of the database. Write it down and store it at someplace you canremember on your <strong>com</strong>puter. This is vital if you create a database outside of Visual Studio2008 that kindly stores the name of the database and related tables in the Server Explorer.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!