Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using Database: A very, very short introduction..

Similar presentations


Presentation on theme: "Using Database: A very, very short introduction.."— Presentation transcript:

1 Using Database: A very, very short introduction.

2 No more play This camp is not a game-programming camp! We should try for more serious programming.

3 With database engine, we can: Store lots of data Do complex search over data And... most important:  Write better games!

4 Reference Most part of this note is from Wikipedia. http://en.wikipedia.org/wiki/SQL

5 SQLSQL SQL stands for "Structured Query Language." It operates on databases with table structures. A few notable commands:  SELECT  INSERT  UPDATE  DELETE

6 Plan for the day Morning:  Using SELECT to query data Afternoon:  Manipulating data with INSERT, UPDATE, DELETE

7 Database ~ Tables A table is a collection of rows. Each row contains a set of columns, called fields.

8 Table structure Each row (or record) contains a set of fields, each of which is of a specific data type.

9 A very simple database We will use only one table! It is a movie show time database, from movieseer. (thanks a lot!)

10 SELECT Syntax:  SELECT [ DISTINCT ] FROM [ WHERE ] [ ORDER BY ] What's that mean?  SELECT FROM ;  SELECT FROM WHERE ;  SELECT DISTINCT FROM WHERE ;  SELECT FROM WHERE ORDER BY ;

11 How could we use this fancy SQL command in C#? Database Engine with SQL capability  MySQL, Access, SQL Server, etc. A bunch of objects:  xxxDbConnection  xxxDbCommand  xxxDbDataReader

12 Connecting to Access We need to use Microsoft JET OLEDB. We use  System.Data.OleDb.OleDbConnection With the following connection string:  Provider=Microsoft.JET.OLEDB.4.0; Data source=

13 OleDbCommand Properties:  CommandText Example: cmd.CommandText = "SELECT DISTINCT theater FROM showtime"; OleDbDataReader reader = cmd.ExecuteReader(); while(reader.Read()) { // your data is in reader["theater"] } reader.Close();

14 More SQL Commands INSERT UPDATE DELETE

15 INSERT Syntax:  INSERT INTO ( ) VALUES ( ) Example:  INSERT INTO showtime (movie,theater,time) VALUES ('The Programmer', 'KAMPANGSAN-SF', #20:00:0#)

16 UPDATE Syntax:  UPDATE SET =, =,... WHERE Example:  UPDATE showtime SET movie="Sad City" WHERE movie = "Sin City";

17 DELETE Syntax:  DELETE FROM WHERE ; Example:  DELETE FROM showtime WHERE movie like "Star%";


Download ppt "Using Database: A very, very short introduction.."

Similar presentations


Ads by Google