Presentation is loading. Please wait.

Presentation is loading. Please wait.

Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#

Similar presentations


Presentation on theme: "Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#"— Presentation transcript:

1 Building and using CASE Tools Data Base with Microsoft SQL-Server and C#

2 common SQL keywords

3 Basic SELECT Query

4 . WHERE Clause

5 . WHERE Clause

6 INSERT Statement

7 UPDATE Statement

8 DELETE Statement

9 SQL-Server Database classes
Namespace System.Data is the root namespace Namespace System.Data.SqlClient contains classes that are optimized to work with Microsoft SQL Server databases. An object of class SqlConnection (namespace System.Data.SqlClient) represents a connection to a data source specifically a SQL Server database. A SqlConnection object keeps track of the location of the data source and any settings that specify how the data source is to be accessed. An object of class SqlCommand (namespace System.Data.SqlClient) represents a SQL command that a DBMS can execute on a database. A program can use SqlCommand objects to manipulate a data source through a SqlConnection.

10 SQL-Server Database classes
The program must open the connection to the data source before executing one or more SqlCommands and close the connection once no further access to the data source is required. Class DataTable (namespace System.Data) represents a table of data. A DataTable contains a collection of DataRows that represent the table's data. A DataTable also has a collection of DataColumns that describe the columns in a table. DataRow and DataColumn are both located in namespace System.Data. An object of class System.Data.DataSet, which consists of a set of DataTables and the relationships among them, represents a cache of data that a program stores temporarily in local memory. The structure of a DataSet mimics the structure of a relational database.

11 SQL server Database

12 Creating SQL Database file And Displaying a Database Table in a DataGridView

13 Create new windows application project

14 Click on add new data source option in data source window

15 In choose data source type dialog box select Dataset then click next

16 In choose your data connection dialog box click on new connection button

17 Select Microsoft SQL Server Database file option as a data source then click on continue button

18 In Add connection dialog box enter a name for the database file ex: database1 then click on ok button

19

20 A massage box will appear to tell you that this is a new database would you like to create it? Click on yes button

21 Now a new database is created with a specific connection string that will be used to connect the application to this database.

22 Click next

23 Click on NO button

24 Click on next

25 Click on previous button

26 Click on finish button

27

28 Open server explorer then click on database1
Open server explorer then click on database1.mdf then right click on Tables and choose Add new Table option

29

30 Add new filed "name" to the table as following

31 To save changes on the table click on update then Click on update database button

32

33 To change table name to "student"

34 Update the database then close the table

35 On data source window right click on database1Dataset then choose Configure data source with wizard then choose tables

36 Then choose table click finish

37

38 Drag and drop student table from data source window to the form

39 Run the program

40 Add new record then click save

41 Remove the record then click save

42 How Data Binding Works The technique through which GUI controls are connected to data sources is known as data binding. The IDE allows controls, such as a DataGridView, to be bound to a data source, such as a DataSet that represents a table in a database. Any changes you make through the application to the underlying data source will automatically be reflected in the way the data is presented in the data-bound control (e.g., the DataGridView). Likewise, modifying the data in the data-bound control and saving the changes updates the underlying data source.

43 Create new windows application then create SQL-server database with following tables
Course int Cno Cmark stId Student int stId Nvarchar(50) stName

44 Drag and drop student table and Add a button “print names” to your form to print all student names as following

45 To print all student names in student table add the following code to the button “print names” event handler

46 Run the program and add the following students to student table

47 Then click the button the following message box will be shown with names of all students

48 Add three textboxes and three labels to the form as following then add new button “Add course” to add new course to table course in the database

49 In button “Add course” event handler add the following code

50 Add new button “print AVG” to the form to find the average for all marks in course table as following

51 Add the following code to button “print AVG” event handler

52 Add the following courses to course table then find the average of all marks

53 Click on print AVG button


Download ppt "Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#"

Similar presentations


Ads by Google