You are on page 1of 15

BASIC SQL COMMANDS September 4, 2018

INSERT QUERY
Insert Query is used to add records to the database

Click “New Query” to show the query designer

Use [Database Name]

Insert into [Table Name] Values (‘[Column 1]’,’[Column 2]’,’[Column 3]’,’[Column n]’)

Press “F5” to execute query


SELECT QUERY
Select Query is used to get records from the database

Click “New Query” to show the query designer

Use [Database Name]

Select * from [Table Name]

Using [Select *] means you are selecting all columns


From the table

Press “F5” to execute query


SELECT QUERY

Click “New Query” to show the query designer

Use [Database Name]

Select [Column Name],[Column Name] from [Table Name]

Press “F5” to execute query


SELECT QUERY

Click “New Query” to show the query designer

Use [Database Name]

Select *from [Table Name] where [ColumnName] = ‘[Value]’

The WHERE clause is used to filter records.


In this example, we searched al records with FirstName = ‘Sample’ And
LastName = ‘Test’

Press “F5” to execute query


UPDATE QUERY
Update Query is used to change/edit a record from the database

Click “New Query” to show the query designer

Use [Database Name]

Update [Table Name] set [Column Name] = ‘[Value]’ where [Column Name] = ‘[Value]’ and [Column Name] = ‘[Value]’

Press “F5” to execute query


DELETE QUERY
Delete Query is used to delete/remove a record from the database

Click “New Query” to show the query designer

Use [Database Name]

Delete from [Table Name] where [Column Name] = ‘[Value]’

Press “F5” to execute query


DATABASE AND September 4, 2018
VB.NET INTEGRATION
SETUP VB.NET CONNECTION
1. Right Click your project in the Solution Explorer
2. Add -> Module
SETUP VB.NET CONNECTION

Enter Module Name then click “Add”


SETUP VB.NET CONNECTION

sa
User ID=

Imports System.Data.Oledb
-Includes the OLEDB library in your project.
OleDbConnection
-Connects your project to the database server using the “connectionString”
OleDbCommand
-Converts your String Query to an SQL Command
OleDbDataAdapter
-Used to exchange data from SQL Server and Project using the OleDBCommand
DataTable
-Stores records from query results
SETUP DATABASE QUERY FUNCTION

Create the public sub Exec()


-This will be used by your entire project to query the database server
Conn.Close()
-Closes the connection
Conn.Open()
-Opens a new connection
INSERTING RECORD TO
DATABASE

Using the “&” sign, strings will be joined end to end.


Example:

Dim s1 as String = “abc”


Dim s2 as String = “def”
Dim s3 as String = s1 & s2

Output:

S3 = “abcdef”
GET RECORDS FROM
DATABASE

For each R as DataRow In dt.Rows


-Loop all records from the query one by one
DELETE RECORD FROM
DATABASE

If ListView1.SelectedItems.Count = 1
-Checks if the user has selected a data from the listview
Listview1.SelectedItems(0).Text
-Data from the first column of the listview
ListView1.SelectedItems(0).SubItems(1).Text
-Data from the second column of the listview

You might also like