0% found this document useful (0 votes)
25 views

With MySQL Connectivity Practical

This Project demo is used to connect VB with SQL

Uploaded by

Desta Dan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

With MySQL Connectivity Practical

This Project demo is used to connect VB with SQL

Uploaded by

Desta Dan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Demo- 5

VBDB Connectivity
By Desta D(Asst. Prof.)
Design GUI Form
Install and Import necessary
packages
• Install VB editor, XAMPP(MySQL server), ADO.Net Connector

• Add neccassary packages MySQL.DATA from Project> Reference>.NET


• Create Databases, Table in the XAMPP
1. create database WSU
2. Create table soistudent(Sid varchar(20), fullname varchar(30), Sex
varchar(10), Programchoice(50)).
3. Insert into soistudent values(‘WSU/Soi/123/13’, ‘Abebe Bekele
Bolla’, ‘MALE’, ‘Cyber Security’)
Code on Submit Button
• NB: Above form import necessary packages then:
Imports MySql.Data.MySqlClient
‘Public Class Form1
Then follow 3 steps:
I. Create Connection
II. Execute SQL statement(Query)
III. Close connection
Create Connection
Dim CONN As MySqlConnection = New
MySqlConnection("Data Source=localhost;Database=wsu;User
ID=root;")
CONN.Open()
Dim COM As MySqlCommand = New MySqlCommand()
COM.Connection = CONN
SQl Query statement
COM.CommandText = "INSERT INTO soistudent(Sid, fullname, Sex,
Programchoice) VALUES ('" & TextBox1.Text & "','" & TextBox2.Text &
"','" & ComboBox1.SelectedItem & "','" & ComboBox2.SelectedItem &
"') "
COM.ExecuteNonQuery()
Close Connection
COM.Dispose()
CONN.Close()
MessageBox.Show("Registered Successfully!", "Register",
MessageBoxButtons.OK, MessageBoxIcon.Information)
VBNET- SQL Connectivity sample
code
• Imports MySql.Data.MySQLClient ’top of code in the form
Dim CONN As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=wsu;User
ID=root;")
CONN.Open()
Dim COM As MySqlCommand = New MySqlCommand()
COM.Connection = CONN
COM.CommandText = "INSERT INTO soistudent(Sid, fullname, Sex, Programchoice) VALUES ('" &
TextBox1.Text & "','" & TextBox2.Text & "','" & ComboBox1.SelectedItem & "','" &
ComboBox2.SelectedItem & "') "
COM.ExecuteNonQuery()
COM.Dispose()
CONN.Close()
MessageBox.Show("Registered Successfully!", "Register", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Reset Button
TextBox1.Clear()
TextBox2.Clear()
ComboBox1.Items.Clear()
ComboBox2.Items.Clear()
Exit Button
Dim MessageString As String = "Do you want to close the form?"
Dim ButtonDialogResult As DialogResult =
MessageBox.Show(MessageString, "Quit?", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
If ButtonDialogResult = Windows.Forms.DialogResult.Yes Then
Me.Close()
End If
Run Your Program(F5)


Enjoy It!!!

You might also like