I'm doing this exercise on VB2010, it's a log-in and the other is an add/edit/delete project.
I've coded the connection and been successful at it somehow, now, the thing is I can't update the database even if I get the confirmation that the record has been added.
I have no idea where the error is.
All I have for now is this block of code for the registration (add/edit/delete) so far:
Imports MySql.Data.MySqlClient
Public Class register
Private Sub register_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
firstnametb.Focus()
Try
If conn.State = ConnectionState.Closed Then
Dim connection As New MySqlConnection("Server = localhost; User Id = root; Password = root; Database = add_edit_delete")
connection.Open()
End If
Catch ex As Exception
MsgBox("Database Error!", MsgBoxStyle.Information, "System Message")
Application.Exit()
End Try
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clrbtn.Click
lastnametb.Text = ""
firstnametb.Text = ""
middletb.Text = ""
agetb.Text = ""
loctb.Text = ""
unametb.Text = ""
pwordtb.Text = ""
cpwordtb.Text = ""
End Sub
Private Sub addbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addbtn.Click
If lastnametb.Text = "" Or firstnametb.Text = "" Or agetb.Text = "" Or loctb.Text = "" Or unametb.Text = "" Or pwordtb.Text = "" Or cpwordtb.Text = "" Then
MsgBox("Please complete the fields!", MsgBoxStyle.Exclamation, "System Message")
Else
If conn.State = ConnectionState.Closed Then
Dim connection As New MySqlConnection("Server = localhost; User Id = root; Password = root; Database = add_edit_delete")
connection.Open()
End If
Try
strSql = "INSERT INTO register(LastName, FirstName, MiddleInitial, Age, Location, Uname, Pword) VALUES('" & lastnametb.Text & "','" & firstnametb.Text & "','" & middletb.Text & "','" & agetb.Text & "','" & loctb.Text & "','" & unametb.Text & "','" & pwordtb.Text & "')"
cmd.CommandText = strSql
cmd.Connection = conn
cmd.ExecuteNonQuery()
MsgBox("Record has been saved!", MsgBoxStyle.Information, "System Message")
conn.Close()
Me.Dispose()
Catch ex As Exception
MsgBox("Unable to save record!", MsgBoxStyle.Critical, "System Message")
conn.Close()
End Try
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Dispose()
End Sub
End Class
Hope someone could help me. :) THANKS! God bless!