Escolar Documentos
Profissional Documentos
Cultura Documentos
Imports MySql.Data.MySqlClient
Public Class Form2
Dim con As New MySqlConnection
Dim result As Integer
Dim cmd As New MySqlCommand
Dim da As New MySqlDataAdapter
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs)
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
End Sub
Private Sub btncreate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles brncreate.Click
con.ConnectionString = ("server=localhost;port=3307;user
id=root;password=123456;database=stud_env")
If (txtname.Text = "") Then
MsgBox("Please fill desired feilds")
Me.Close()
ElseIf (txtbranch.Text = "") Then
MsgBox("Please fill desired feilds")
Me.Close()
ElseIf (txtcity.Text = "") Then
MsgBox("Please fill desired feilds")
Me.Close()
ElseIf (txtstate.Text = "") Then
MsgBox("Please fill desired feilds")
Me.Close()
Else
Try
con.Open()
cmd.Connection = con
cmd.CommandText = "insert into
stud_details(stud_name,stud_branch,stud_city,stud_state) values('" &
txtname.Text & "','" & txtbranch.Text & "','" & txtcity.Text & "','" &
txtstate.Text & "');"
result = cmd.ExecuteNonQuery
If result = 0 Then
MsgBox("Data has been inserted")
Else
MsgBox("Successfully saved")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()
End If
End Sub
Private Sub DataGridView1_CellContentClick_1(ByVal sender As
System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
Handles dtgstud.CellContentClick
End Sub
Private Sub btnread_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnread.Click
con.ConnectionString = ("server=localhost;port=3307;user
id=root;password=123456;database=stud_env")
Try
con.Open()
cmd.Connection = con
cmd.CommandText = "select * from stud_details"
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()
da.Dispose()
filltable(dtgstud)
End Sub
Public Sub filltable1(ByVal dtgrd As Object)
Dim publictable As New DataTable
Try
da.SelectCommand = cmd
da.Fill(publictable)
dtgstud.DataSource = publictable
dtgstud.Columns(0).Visible = True
da.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnexit.Click
Me.Close()
Me.con.Close()
End Sub
Private Sub btnsearch_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnsearch.Click
con.ConnectionString = ("server=localhost;port=3307;user
id=root;password=123456;database=stud_env")
Try
con.Open()
cmd.Connection = con
cmd.CommandText = "select * from stud_details where stud_id='" &
txtstudid.Text & "'"
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()
da.Dispose()
filltable(dtgstud)
End Sub
Public Sub filltable(ByVal dtgrd As Object)
Dim publictable As New DataTable
Try
da.SelectCommand = cmd
da.Fill(publictable)
dtgstud.DataSource = publictable
dtgstud.Columns(0).Visible = True
da.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class