0% found this document useful (0 votes)
46 views3 pages

Dim As New: Oledbconnection Oledbconnection

The document provides code samples for performing common database operations in Visual Basic, including adding, deleting, updating, and viewing records. It explains how to open and close database connections, execute queries, and display results in a DataGridView. Key points covered include using Imports to reference the OleDb namespace, building SQL queries using string concatenation, and showing messages on successful operations.

Uploaded by

narender s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views3 pages

Dim As New: Oledbconnection Oledbconnection

The document provides code samples for performing common database operations in Visual Basic, including adding, deleting, updating, and viewing records. It explains how to open and close database connections, execute queries, and display results in a DataGridView. Key points covered include using Imports to reference the OleDb namespace, building SQL queries using string concatenation, and showing messages on successful operations.

Uploaded by

narender s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

For closing any form you use

Me.Close()
For calling any form FormName.Show()
For first form alone dont give Me.Close give Me.hide
For completely closing the program startupform.Close()

Any database form should have this statement in first line of the form
Imports System.Data.OleDb

ADD:
BELOW PROGRAM variable1 & variable2 are string and variable3 is a number

Dim connection As OleDbConnection = New


OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=COMPLETE_PATH\DATABASE_FILE_NAME.accdb")
connection.Open()
Dim command As OleDbCommand = New OleDbCommand("INSERT INTO
table_name(field1,field2,field3) VALUES('" & variable1 & "','" & variable2 & "'," & variable3
& ")", connection)
command.ExecuteNonQuery()
MessageBox.Show(Added Successfully")
connection.Close()
Me.Close()
Previous_From.Show()

DELETE:
BELOW PROGRAM variable is the variable based on which we are going to delete a record

Dim connection As OleDbConnection = New


OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=COMPLETE_PATH\DATABASE_FILE_NAME.accdb")
connection.Open()
Dim command As OleDbCommand = New OleDbCommand("DELETE FROM table_name
WHERE field=('" & variable & "')", connection)
command.ExecuteNonQuery()
MessageBox.Show("Deleted Successfully")
connection.Close()
Me.Close()
Previous_From.Show()

UPDATE:
BELOW PROGRAM variable is the variable based on which we are going to update a record
filed filed1

Dim connection As OleDbConnection = New


OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=COMPLETE_PATH\DATABASE_FILE_NAME.accdb")
connection.Open()
Dim command As OleDbCommand = New OleDbCommand("UPDATE table_name SET
field1=('" & variable1 & "') WHERE field=('" & variable & "')", connection)
command.ExecuteNonQuery()
FOR MULTIPLE UPDATE USE SAME COMMANDS(BOTH LINES) WITH OUT Dim
command As OleDbCommand USE command
MessageBox.Show("Updated Successfully")
connection.Close()
Me.Close()
Previous_From.Show()

VIEW:
Viewing the complete record from a database in table called DataGridView1

Dim connection As OleDbConnection = New


OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=
COMPLETE_PATH\DATABASE_FILE_NAME.accdb")
connection.Open()
Dim command As OleDbCommand = New OleDbCommand("SELECT * FROM table_name",
connection)
Dim dataAdapter As OleDbDataAdapter = New OleDbDataAdapter(command)
Dim dataTable As DataTable = New DataTable
dataAdapter.Fill(dataTable)
DataGridView1.DataSource = dataTable
connection.Close()

VIEWing a Required Recordset:


Viewing the required record from a database in table called DataGridView1

Dim connection As OleDbConnection = New


OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=
COMPLETE_PATH\DATABASE_FILE_NAME.accdb")
connection.Open()
Dim command As OleDbCommand = New OleDbCommand("SELECT * FROM table_name
WHERE field=('" & variable & "')", connection)
Dim dataAdapter As OleDbDataAdapter = New OleDbDataAdapter(command)
Dim dataTable As DataTable = New DataTable
dataAdapter.Fill(dataTable)
DataGridView1.DataSource = dataTable
connection.Close()
syntax for a number variable in querying
" & number_variable & "

syntax for a string(text) variable in querying


" & number_variable & "

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy