Gis2409 - .Net Assignment
Gis2409 - .Net Assignment
.NET FRAMEWORK
TOPIC :- SQL namespace, SQL methods, Creating table, insert, update, delete
BY
SMRUTHI M, GIS2409
1ST METCH
SQL NAMESPACE
Class Role
ADO.NET Workflow
4. Read Data: Use SQL Data Reader or Dataset with SQL Data Adapter
1. Open ()
C#
2. Close () / Dispose ()
C#
conn. Close (); // or use conn. Dispose (); reader. Close ().
3. Execute Reader ()
• Use: Executes a SQL query that returns rows of data (like SELECT) and returns a
SQL Data Reader.
C#
SQL Command cmd = new SQL Command ("SELECT * FROM Students", conn);
4. Execute non-query ()
• Use: Executes SQL commands that don’t return data (like INSERT, UPDATE,
DELETE).
C#
SQL Command cmd = new SQL Command ("DELETE FROM Students WHERE Id=1",
conn);int rows = cmd .Execute Non Query ();
5. ExecuteScalar ()
• Use: Executes a query that returns a single value (like COUNT, MAX, etc.).
C#
SQL Command cmd = new SQL Command ("SELECT COUNT (*) FROM Students",
conn); int count = (int)cmd. Execute Scalar ();
6. Fill()
C#
SQL Data Adapter = new SQL Data Adapter ("SELECT * FROM Students", conn);
C#
C#
The CREATE TABLE statement is used in SQL to define a new table in the database. A
table is a collection of rows and columns, where each column has a data type,
name, and optionally, constraints (like primary key or not null).
Syntax:
...
);
Component Description
column
The name of each column (field)
name
datatype The type of data allowed in that column (e.g., INT, VARCHAR, DATE)
Rules applied to the column like PRIMARY KEY, NOT NULL, UNIQUE,
constraint
DEFAULT, FOREIGN KEY
INSERT – Add New Data
Syntax
The first way specifies both the column names and the values to be inserted.
If you are adding values for all the columns of the table, then no need to specify the column
names in the SQL query. However, make sure that the order of the values is in the same
order as the columns in the table.
3.
4. '2nd way
UPDATE TABLE
Syntax
1. UPDATE table_name
2. SET column1 = value1, column2 = value2, ...
3. WHERE condition;
The DELETE statement is used to delete existing records in a table for a particular Record.
Syntax
Example