Join 309,249 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,544 people online right now. Registration is fast and FREE... Join Now!
Imports System Imports System.Data Imports System.Windows.Forms Imports MySql.Data.MySqlClient Public Class Registrar Private myConn As MySqlConnection Private myConn2 As MySqlConnection Private myConn3 As MySqlConnection Private myConn4 As MySqlConnection Private myConn5 As MySqlConnection Private myCmd As New MySqlCommand Private myCmd2 As New MySqlCommand Private myCmd3 As New MySqlCommand Private myCmd4 As New MySqlCommand Private myCmd5 As New MySqlCommand Private constr As String
'Connection Function for Openning Database Private Sub Connectstr()
Dim strConn As String strConn = "server=localhost;database=asirs_dbase;uid=root;pwd=;" myConn = New MySqlConnection myConn.ConnectionString = strConn
myConn2 = New MySqlConnection myConn2.ConnectionString = strConn
myConn3 = New MySqlConnection myConn3.ConnectionString = strConn
myConn4 = New MySqlConnection myConn4.ConnectionString = strConn
myConn5 = New MySqlConnection myConn5.ConnectionString = strConn
Try myConn.Open() Catch ex As Exception MessageBox.Show(ex.ToString()) End Try
Try myConn2.Open() Catch ex As Exception MessageBox.Show(ex.ToString()) End Try Try myConn3.Open() Catch ex As Exception MessageBox.Show(ex.ToString()) End Try Try myConn4.Open() Catch ex As Exception MessageBox.Show(ex.ToString()) End Try Try myConn5.Open() Catch ex As Exception MessageBox.Show(ex.ToString()) End Try End Sub 'Connection Function for Closing Database Private Sub CloseConnection() myConn.Close() myConn = Nothing End Sub Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged 'if the student is old studnt then only few boxes/textboxes,comboboxes letting the user to input his ID Number for homing features '(when ID Number is inputed the information of the student will automatically pop up to the remaining textboxes). If CheckBox1.Checked = True Then CheckBox2.Enabled = False CheckBox3.Enabled = False btnupdate.Enabled = True TextBox2.Enabled = False TextBox3.Enabled = False TextBox4.Enabled = False TextBox5.Enabled = False TextBox6.Enabled = False TextBox7.Enabled = False TextBox8.Enabled = False TextBox9.Enabled = False TextBox10.Enabled = False TextBox11.Enabled = False TextBox12.Enabled = False TextBox13.Enabled = False TextBox14.Enabled = False TextBox15.Enabled = False TextBox16.Enabled = False TextBox17.Enabled = False TextBox18.Enabled = False TextBox19.Enabled = False TextBox20.Enabled = False TextBox21.Enabled = False TextBox22.Enabled = False TextBox23.Enabled = False TextBox24.Enabled = False TextBox25.Enabled = False TextBox26.Enabled = False TextBox27.Enabled = False TextBox28.Enabled = True TextBox29.Enabled = False ComboBox1.Enabled = True ComboBox2.Enabled = True ComboBox3.Enabled = True ComboBox4.Enabled = True ComboBox5.Enabled = True TextBox1.Enabled = True ElseIf CheckBox1.Checked = False Then CheckBox2.Enabled = True CheckBox3.Enabled = True btnupdate.Enabled = False TextBox2.Enabled = False TextBox3.Enabled = False TextBox4.Enabled = False TextBox5.Enabled = False TextBox6.Enabled = False TextBox7.Enabled = False TextBox8.Enabled = False TextBox9.Enabled = False TextBox10.Enabled = False TextBox11.Enabled = False TextBox12.Enabled = False TextBox13.Enabled = False TextBox14.Enabled = False TextBox15.Enabled = False TextBox16.Enabled = False TextBox17.Enabled = False TextBox18.Enabled = False TextBox19.Enabled = False TextBox20.Enabled = False TextBox21.Enabled = False TextBox22.Enabled = False TextBox23.Enabled = False TextBox24.Enabled = False TextBox25.Enabled = False TextBox26.Enabled = False TextBox27.Enabled = False TextBox28.Enabled = False TextBox29.Enabled = False TextBox1.Enabled = False ComboBox1.Enabled = False ComboBox2.Enabled = False ComboBox3.Enabled = False ComboBox4.Enabled = False ComboBox5.Enabled = False End If End Sub Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged 'if the student is New all the boxes are enabled giving the user to input data in them for storages If CheckBox2.Checked = True Then CheckBox1.Enabled = False CheckBox3.Enabled = False btnreg.Enabled = True TextBox2.Enabled = True TextBox3.Enabled = True TextBox4.Enabled = True TextBox5.Enabled = True TextBox6.Enabled = True TextBox7.Enabled = True TextBox8.Enabled = True TextBox9.Enabled = True TextBox10.Enabled = True TextBox11.Enabled = True TextBox12.Enabled = True TextBox13.Enabled = True TextBox14.Enabled = True TextBox15.Enabled = True TextBox16.Enabled = True TextBox17.Enabled = True TextBox18.Enabled = True TextBox19.Enabled = True TextBox20.Enabled = True TextBox21.Enabled = True TextBox22.Enabled = True TextBox23.Enabled = True TextBox24.Enabled = True TextBox25.Enabled = True TextBox26.Enabled = True TextBox27.Enabled = True TextBox28.Enabled = True TextBox29.Enabled = True TextBox1.Enabled = True ComboBox1.Enabled = True ComboBox2.Enabled = True ComboBox3.Enabled = True ComboBox4.Enabled = True ComboBox5.Enabled = True ElseIf CheckBox2.Checked = False Then CheckBox1.Enabled = True CheckBox3.Enabled = True btnreg.Enabled = False TextBox2.Enabled = False TextBox3.Enabled = False TextBox4.Enabled = False TextBox5.Enabled = False TextBox6.Enabled = False TextBox7.Enabled = False TextBox8.Enabled = False TextBox9.Enabled = False TextBox10.Enabled = False TextBox11.Enabled = False TextBox12.Enabled = False TextBox13.Enabled = False TextBox14.Enabled = False TextBox15.Enabled = False TextBox16.Enabled = False TextBox17.Enabled = False TextBox18.Enabled = False TextBox19.Enabled = False TextBox20.Enabled = False TextBox21.Enabled = False TextBox22.Enabled = False TextBox23.Enabled = False TextBox24.Enabled = False TextBox25.Enabled = False TextBox26.Enabled = False TextBox27.Enabled = False TextBox28.Enabled = False TextBox29.Enabled = False TextBox1.Enabled = False ComboBox1.Enabled = False ComboBox2.Enabled = False ComboBox3.Enabled = False ComboBox4.Enabled = False ComboBox5.Enabled = False End If End Sub Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged If CheckBox3.Checked = True Then CheckBox1.Enabled = False CheckBox2.Enabled = False btnupdate.Enabled = True TextBox2.Enabled = True TextBox3.Enabled = True TextBox4.Enabled = True TextBox5.Enabled = True TextBox6.Enabled = True TextBox7.Enabled = True TextBox8.Enabled = True TextBox9.Enabled = True TextBox10.Enabled = True TextBox11.Enabled = True TextBox12.Enabled = True TextBox13.Enabled = True TextBox14.Enabled = True TextBox15.Enabled = True TextBox16.Enabled = True TextBox17.Enabled = True TextBox18.Enabled = True TextBox19.Enabled = True TextBox20.Enabled = True TextBox21.Enabled = True TextBox22.Enabled = True TextBox23.Enabled = True TextBox24.Enabled = True TextBox25.Enabled = True TextBox26.Enabled = True TextBox27.Enabled = True TextBox28.Enabled = True TextBox29.Enabled = True TextBox1.Enabled = True ComboBox1.Enabled = True ComboBox2.Enabled = True ComboBox3.Enabled = True ComboBox4.Enabled = True ComboBox5.Enabled = True ElseIf CheckBox3.Checked = False Then CheckBox1.Enabled = True CheckBox2.Enabled = True btnupdate.Enabled = False TextBox2.Enabled = False TextBox3.Enabled = False TextBox4.Enabled = False TextBox5.Enabled = False TextBox6.Enabled = False TextBox7.Enabled = False TextBox8.Enabled = False TextBox9.Enabled = False TextBox10.Enabled = False TextBox11.Enabled = False TextBox12.Enabled = False TextBox13.Enabled = False TextBox14.Enabled = False TextBox15.Enabled = False TextBox16.Enabled = False TextBox17.Enabled = False TextBox18.Enabled = False TextBox19.Enabled = False TextBox20.Enabled = False TextBox21.Enabled = False TextBox22.Enabled = False TextBox23.Enabled = False TextBox24.Enabled = False TextBox25.Enabled = False TextBox26.Enabled = False TextBox27.Enabled = False TextBox28.Enabled = False TextBox29.Enabled = False TextBox1.Enabled = False ComboBox1.Enabled = False ComboBox2.Enabled = False ComboBox3.Enabled = False ComboBox4.Enabled = False ComboBox5.Enabled = False End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.Close() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click End End Sub Private Sub Registrar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'connects to the dbase as soon as the form loads up(not yet complete due to some luck of codes and source codes). Connectstr() Dim searchSTR As String searchSTR = "SELECT * FROM studentinfo" Dim myCmd As New MySqlCommand(searchSTR, myConn) Dim myReader As MySqlDataReader myReader = myCmd.ExecuteReader CloseConnection() TextBox1.Enabled = False TextBox2.Enabled = False TextBox3.Enabled = False TextBox4.Enabled = False TextBox5.Enabled = False TextBox6.Enabled = False TextBox7.Enabled = False TextBox8.Enabled = False TextBox9.Enabled = False TextBox10.Enabled = False TextBox11.Enabled = False TextBox12.Enabled = False TextBox13.Enabled = False TextBox14.Enabled = False TextBox15.Enabled = False TextBox16.Enabled = False TextBox17.Enabled = False TextBox18.Enabled = False TextBox19.Enabled = False TextBox20.Enabled = False TextBox21.Enabled = False TextBox22.Enabled = False TextBox23.Enabled = False TextBox24.Enabled = False TextBox25.Enabled = False TextBox26.Enabled = False TextBox27.Enabled = False TextBox28.Enabled = False TextBox29.Enabled = False ComboBox1.Enabled = False ComboBox2.Enabled = False ComboBox3.Enabled = False ComboBox4.Enabled = False ComboBox5.Enabled = False End Sub Private Sub btnreg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnreg.Click Dim mycmdSave As MySqlCommand Dim saveStr As String Dim searchSTR As String Dim Found As Boolean Try 'this are my codes in inserting in multiple tables(5 tables to be exact, how could I make it work. Connectstr() searchSTR = "SELECT studentinfo.*, academicrecords.*,personalinfo.*,studentguardian.*,parents.* from studentinfo,inner join StudentId on academicrecords.StudentId = studentinfo.StudentId,inner join StudentId on personalinfo.StudentId = studentinfo.StudentId,inner join StudentId on studentguardian.StudentId=studentinfo.StudentI,inner join StudentId on parents.StudentId=studentinfo.StudentId" Dim myCmd As New MySqlCommand(searchSTR, myConn) Dim myReader As MySqlDataReader myReader = myCmd.ExecuteReader While myReader.Read Found = True End While
If Found = False Then 'if one of the textboxes are not filled then this message below will inform the user that one of the fileds have no values/datas inputed in it. If (TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Or TextBox8.Text = "" Or TextBox9.Text = "" Or TextBox10.Text = "" Or TextBox11.Text = "" Or TextBox12.Text = "" Or TextBox13.Text = "" Or TextBox14.Text = "" Or TextBox15.Text = "" Or TextBox16.Text = "" Or TextBox17.Text = "" Or TextBox18.Text = "" Or TextBox19.Text = "" Or TextBox20.Text = "" Or TextBox21.Text = "" Or TextBox22.Text = "" Or TextBox23.Text = "" Or TextBox24.Text = "" Or TextBox25.Text = "" Or TextBox26.Text = "" Or TextBox27.Text = "" Or TextBox29.Text = "") Then MsgBox("Please Fill Up All the Neccesary Fields...!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "WARNING...!") Else CloseConnection() Connectstr() With mycmdSave mycmdSave = New MySqlCommand mycmdSave.Connection = Me.myConn mycmdSave.CommandType = CommandType.Text 'data are inputed inside 4 different tables at the same time the tables studentinfo,academicrecords,personalinfo and parents saveStr = "Insert Into studentinfo Values ('" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & ComboBox1.Text & "','" & ComboBox3.Text & "','" & ComboBox2.Text & "','" & ComboBox4.Text & "')" mycmdSave.CommandText = saveStr mycmdSave.ExecuteNonQuery() saveStr = "insert into academicrecords values('" & TextBox20.Text & "','" & TextBox21.Text & "','" & TextBox22.Text & "','" & TextBox23.Text & "','" & TextBox24.Text & "','" & TextBox25.Text & "','" & TextBox26.Text & "','" & TextBox27.Text & "') " mycmdSave.CommandText = saveStr mycmdSave.ExecuteNonQuery() saveStr = "insert into personalinfo values('" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox29.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "')" mycmdSave.CommandText = saveStr mycmdSave.ExecuteNonQuery() saveStr = "insert into parents values('" & TextBox11.Text & "','" & TextBox12.Text & "','" & TextBox13.Text & "','" & TextBox14.Text & "','" & TextBox15.Text & "')insert into studentguardian values ('" & TextBox16.Text & "','" & TextBox17.Text & "','" & TextBox18.Text & "','" & TextBox19.Text & "')" mycmdSave.CommandText = saveStr mycmdSave.ExecuteNonQuery()
mycmdSave.CommandText = saveStr mycmdSave.ExecuteNonQuery() mycmdSave.Dispose() End With MsgBox("Records have been Saved...!", MsgBoxStyle.Information, "Saving...") TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox6.Text = "" TextBox7.Text = "" TextBox8.Text = "" TextBox9.Text = "" TextBox10.Text = "" TextBox11.Text = "" TextBox12.Text = "" TextBox13.Text = "" TextBox14.Text = "" TextBox15.Text = "" TextBox16.Text = "" TextBox17.Text = "" TextBox18.Text = "" TextBox19.Text = "" TextBox20.Text = "" TextBox21.Text = "" TextBox22.Text = "" TextBox23.Text = "" TextBox24.Text = "" TextBox25.Text = "" TextBox26.Text = "" TextBox27.Text = "" TextBox29.Text = "" End If Else MsgBox("Record Already Exists...!", MsgBoxStyle.Critical, "WARNING...!") End If 'Closing Connection Strings myReader.Close() CloseConnection() myCmd.Dispose() myCmd = Nothing Catch End Try End Sub Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
Imports System Imports System.Data Imports System.Windows.Forms Imports MySql.Data.MySqlClient Public Class Registrar Private myConn As MySqlConnection Private myConn2 As MySqlConnection Private myConn3 As MySqlConnection Private myConn4 As MySqlConnection Private myConn5 As MySqlConnection Private myCmd As New MySqlCommand Private myCmd2 As New MySqlCommand Private myCmd3 As New MySqlCommand Private myCmd4 As New MySqlCommand Private myCmd5 As New MySqlCommand Private constr As String
'Connection Function for Openning Database Private Sub Connectstr()
Dim strConn As String strConn = "server=localhost;database=asirs_dbase;uid=root;pwd=;" myConn = New MySqlConnection myConn.ConnectionString = strConn
myConn2 = New MySqlConnection myConn2.ConnectionString = strConn
myConn3 = New MySqlConnection myConn3.ConnectionString = strConn
myConn4 = New MySqlConnection myConn4.ConnectionString = strConn
myConn5 = New MySqlConnection myConn5.ConnectionString = strConn
Try myConn.Open() Catch ex As Exception MessageBox.Show(ex.ToString()) End Try
Try myConn2.Open() Catch ex As Exception MessageBox.Show(ex.ToString()) End Try Try myConn3.Open() Catch ex As Exception MessageBox.Show(ex.ToString()) End Try Try myConn4.Open() Catch ex As Exception MessageBox.Show(ex.ToString()) End Try Try myConn5.Open() Catch ex As Exception MessageBox.Show(ex.ToString()) End Try End Sub 'Connection Function for Closing Database Private Sub CloseConnection() myConn.Close() myConn = Nothing End Sub Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged 'if the student is old studnt then only few boxes/textboxes,comboboxes letting the user to input his ID Number for homing features '(when ID Number is inputed the information of the student will automatically pop up to the remaining textboxes). If CheckBox1.Checked = True Then CheckBox2.Enabled = False CheckBox3.Enabled = False btnupdate.Enabled = True TextBox2.Enabled = False TextBox3.Enabled = False TextBox4.Enabled = False TextBox5.Enabled = False TextBox6.Enabled = False TextBox7.Enabled = False TextBox8.Enabled = False TextBox9.Enabled = False TextBox10.Enabled = False TextBox11.Enabled = False TextBox12.Enabled = False TextBox13.Enabled = False TextBox14.Enabled = False TextBox15.Enabled = False TextBox16.Enabled = False TextBox17.Enabled = False TextBox18.Enabled = False TextBox19.Enabled = False TextBox20.Enabled = False TextBox21.Enabled = False TextBox22.Enabled = False TextBox23.Enabled = False TextBox24.Enabled = False TextBox25.Enabled = False TextBox26.Enabled = False TextBox27.Enabled = False TextBox28.Enabled = True TextBox29.Enabled = False ComboBox1.Enabled = True ComboBox2.Enabled = True ComboBox3.Enabled = True ComboBox4.Enabled = True ComboBox5.Enabled = True TextBox1.Enabled = True ElseIf CheckBox1.Checked = False Then CheckBox2.Enabled = True CheckBox3.Enabled = True btnupdate.Enabled = False TextBox2.Enabled = False TextBox3.Enabled = False TextBox4.Enabled = False TextBox5.Enabled = False TextBox6.Enabled = False TextBox7.Enabled = False TextBox8.Enabled = False TextBox9.Enabled = False TextBox10.Enabled = False TextBox11.Enabled = False TextBox12.Enabled = False TextBox13.Enabled = False TextBox14.Enabled = False TextBox15.Enabled = False TextBox16.Enabled = False TextBox17.Enabled = False TextBox18.Enabled = False TextBox19.Enabled = False TextBox20.Enabled = False TextBox21.Enabled = False TextBox22.Enabled = False TextBox23.Enabled = False TextBox24.Enabled = False TextBox25.Enabled = False TextBox26.Enabled = False TextBox27.Enabled = False TextBox28.Enabled = False TextBox29.Enabled = False TextBox1.Enabled = False ComboBox1.Enabled = False ComboBox2.Enabled = False ComboBox3.Enabled = False ComboBox4.Enabled = False ComboBox5.Enabled = False End If End Sub Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged 'if the student is New all the boxes are enabled giving the user to input data in them for storages If CheckBox2.Checked = True Then CheckBox1.Enabled = False CheckBox3.Enabled = False btnreg.Enabled = True TextBox2.Enabled = True TextBox3.Enabled = True TextBox4.Enabled = True TextBox5.Enabled = True TextBox6.Enabled = True TextBox7.Enabled = True TextBox8.Enabled = True TextBox9.Enabled = True TextBox10.Enabled = True TextBox11.Enabled = True TextBox12.Enabled = True TextBox13.Enabled = True TextBox14.Enabled = True TextBox15.Enabled = True TextBox16.Enabled = True TextBox17.Enabled = True TextBox18.Enabled = True TextBox19.Enabled = True TextBox20.Enabled = True TextBox21.Enabled = True TextBox22.Enabled = True TextBox23.Enabled = True TextBox24.Enabled = True TextBox25.Enabled = True TextBox26.Enabled = True TextBox27.Enabled = True TextBox28.Enabled = True TextBox29.Enabled = True TextBox1.Enabled = True ComboBox1.Enabled = True ComboBox2.Enabled = True ComboBox3.Enabled = True ComboBox4.Enabled = True ComboBox5.Enabled = True ElseIf CheckBox2.Checked = False Then CheckBox1.Enabled = True CheckBox3.Enabled = True btnreg.Enabled = False TextBox2.Enabled = False TextBox3.Enabled = False TextBox4.Enabled = False TextBox5.Enabled = False TextBox6.Enabled = False TextBox7.Enabled = False TextBox8.Enabled = False TextBox9.Enabled = False TextBox10.Enabled = False TextBox11.Enabled = False TextBox12.Enabled = False TextBox13.Enabled = False TextBox14.Enabled = False TextBox15.Enabled = False TextBox16.Enabled = False TextBox17.Enabled = False TextBox18.Enabled = False TextBox19.Enabled = False TextBox20.Enabled = False TextBox21.Enabled = False TextBox22.Enabled = False TextBox23.Enabled = False TextBox24.Enabled = False TextBox25.Enabled = False TextBox26.Enabled = False TextBox27.Enabled = False TextBox28.Enabled = False TextBox29.Enabled = False TextBox1.Enabled = False ComboBox1.Enabled = False ComboBox2.Enabled = False ComboBox3.Enabled = False ComboBox4.Enabled = False ComboBox5.Enabled = False End If End Sub Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged If CheckBox3.Checked = True Then CheckBox1.Enabled = False CheckBox2.Enabled = False btnupdate.Enabled = True TextBox2.Enabled = True TextBox3.Enabled = True TextBox4.Enabled = True TextBox5.Enabled = True TextBox6.Enabled = True TextBox7.Enabled = True TextBox8.Enabled = True TextBox9.Enabled = True TextBox10.Enabled = True TextBox11.Enabled = True TextBox12.Enabled = True TextBox13.Enabled = True TextBox14.Enabled = True TextBox15.Enabled = True TextBox16.Enabled = True TextBox17.Enabled = True TextBox18.Enabled = True TextBox19.Enabled = True TextBox20.Enabled = True TextBox21.Enabled = True TextBox22.Enabled = True TextBox23.Enabled = True TextBox24.Enabled = True TextBox25.Enabled = True TextBox26.Enabled = True TextBox27.Enabled = True TextBox28.Enabled = True TextBox29.Enabled = True TextBox1.Enabled = True ComboBox1.Enabled = True ComboBox2.Enabled = True ComboBox3.Enabled = True ComboBox4.Enabled = True ComboBox5.Enabled = True ElseIf CheckBox3.Checked = False Then CheckBox1.Enabled = True CheckBox2.Enabled = True btnupdate.Enabled = False TextBox2.Enabled = False TextBox3.Enabled = False TextBox4.Enabled = False TextBox5.Enabled = False TextBox6.Enabled = False TextBox7.Enabled = False TextBox8.Enabled = False TextBox9.Enabled = False TextBox10.Enabled = False TextBox11.Enabled = False TextBox12.Enabled = False TextBox13.Enabled = False TextBox14.Enabled = False TextBox15.Enabled = False TextBox16.Enabled = False TextBox17.Enabled = False TextBox18.Enabled = False TextBox19.Enabled = False TextBox20.Enabled = False TextBox21.Enabled = False TextBox22.Enabled = False TextBox23.Enabled = False TextBox24.Enabled = False TextBox25.Enabled = False TextBox26.Enabled = False TextBox27.Enabled = False TextBox28.Enabled = False TextBox29.Enabled = False TextBox1.Enabled = False ComboBox1.Enabled = False ComboBox2.Enabled = False ComboBox3.Enabled = False ComboBox4.Enabled = False ComboBox5.Enabled = False End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.Close() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click End End Sub Private Sub Registrar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'connects to the dbase as soon as the form loads up(not yet complete due to some luck of codes and source codes). Connectstr() Dim searchSTR As String searchSTR = "SELECT * FROM studentinfo" Dim myCmd As New MySqlCommand(searchSTR, myConn) Dim myReader As MySqlDataReader myReader = myCmd.ExecuteReader CloseConnection() TextBox1.Enabled = False TextBox2.Enabled = False TextBox3.Enabled = False TextBox4.Enabled = False TextBox5.Enabled = False TextBox6.Enabled = False TextBox7.Enabled = False TextBox8.Enabled = False TextBox9.Enabled = False TextBox10.Enabled = False TextBox11.Enabled = False TextBox12.Enabled = False TextBox13.Enabled = False TextBox14.Enabled = False TextBox15.Enabled = False TextBox16.Enabled = False TextBox17.Enabled = False TextBox18.Enabled = False TextBox19.Enabled = False TextBox20.Enabled = False TextBox21.Enabled = False TextBox22.Enabled = False TextBox23.Enabled = False TextBox24.Enabled = False TextBox25.Enabled = False TextBox26.Enabled = False TextBox27.Enabled = False TextBox28.Enabled = False TextBox29.Enabled = False ComboBox1.Enabled = False ComboBox2.Enabled = False ComboBox3.Enabled = False ComboBox4.Enabled = False ComboBox5.Enabled = False End Sub Private Sub btnreg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnreg.Click Dim mycmdSave As MySqlCommand Dim saveStr As String Dim searchSTR As String Dim Found As Boolean Try 'this are my codes in inserting in multiple tables(5 tables to be exact, how could I make it work. Connectstr() searchSTR = "SELECT studentinfo.*, academicrecords.*,personalinfo.*,studentguardian.*,parents.* from studentinfo,inner join StudentId on academicrecords.StudentId = studentinfo.StudentId,inner join StudentId on personalinfo.StudentId = studentinfo.StudentId,inner join StudentId on studentguardian.StudentId=studentinfo.StudentI,inner join StudentId on parents.StudentId=studentinfo.StudentId" Dim myCmd As New MySqlCommand(searchSTR, myConn) Dim myReader As MySqlDataReader myReader = myCmd.ExecuteReader While myReader.Read Found = True End While
If Found = False Then 'if one of the textboxes are not filled then this message below will inform the user that one of the fileds have no values/datas inputed in it. If (TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Or TextBox8.Text = "" Or TextBox9.Text = "" Or TextBox10.Text = "" Or TextBox11.Text = "" Or TextBox12.Text = "" Or TextBox13.Text = "" Or TextBox14.Text = "" Or TextBox15.Text = "" Or TextBox16.Text = "" Or TextBox17.Text = "" Or TextBox18.Text = "" Or TextBox19.Text = "" Or TextBox20.Text = "" Or TextBox21.Text = "" Or TextBox22.Text = "" Or TextBox23.Text = "" Or TextBox24.Text = "" Or TextBox25.Text = "" Or TextBox26.Text = "" Or TextBox27.Text = "" Or TextBox29.Text = "") Then MsgBox("Please Fill Up All the Neccesary Fields...!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "WARNING...!") Else CloseConnection() Connectstr() With mycmdSave mycmdSave = New MySqlCommand mycmdSave.Connection = Me.myConn mycmdSave.CommandType = CommandType.Text 'data are inputed inside 4 different tables at the same time the tables studentinfo,academicrecords,personalinfo and parents saveStr = "Insert Into studentinfo Values ('" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & ComboBox1.Text & "','" & ComboBox3.Text & "','" & ComboBox2.Text & "','" & ComboBox4.Text & "')" mycmdSave.CommandText = saveStr mycmdSave.ExecuteNonQuery() saveStr = "insert into academicrecords values('" & TextBox20.Text & "','" & TextBox21.Text & "','" & TextBox22.Text & "','" & TextBox23.Text & "','" & TextBox24.Text & "','" & TextBox25.Text & "','" & TextBox26.Text & "','" & TextBox27.Text & "') " mycmdSave.CommandText = saveStr mycmdSave.ExecuteNonQuery() saveStr = "insert into personalinfo values('" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox29.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "')" mycmdSave.CommandText = saveStr mycmdSave.ExecuteNonQuery() saveStr = "insert into parents values('" & TextBox11.Text & "','" & TextBox12.Text & "','" & TextBox13.Text & "','" & TextBox14.Text & "','" & TextBox15.Text & "')insert into studentguardian values ('" & TextBox16.Text & "','" & TextBox17.Text & "','" & TextBox18.Text & "','" & TextBox19.Text & "')" mycmdSave.CommandText = saveStr mycmdSave.ExecuteNonQuery()
mycmdSave.CommandText = saveStr mycmdSave.ExecuteNonQuery() mycmdSave.Dispose() End With MsgBox("Records have been Saved...!", MsgBoxStyle.Information, "Saving...") TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox6.Text = "" TextBox7.Text = "" TextBox8.Text = "" TextBox9.Text = "" TextBox10.Text = "" TextBox11.Text = "" TextBox12.Text = "" TextBox13.Text = "" TextBox14.Text = "" TextBox15.Text = "" TextBox16.Text = "" TextBox17.Text = "" TextBox18.Text = "" TextBox19.Text = "" TextBox20.Text = "" TextBox21.Text = "" TextBox22.Text = "" TextBox23.Text = "" TextBox24.Text = "" TextBox25.Text = "" TextBox26.Text = "" TextBox27.Text = "" TextBox29.Text = "" End If Else MsgBox("Record Already Exists...!", MsgBoxStyle.Critical, "WARNING...!") End If 'Closing Connection Strings myReader.Close() CloseConnection() myCmd.Dispose() myCmd = Nothing Catch End Try End Sub Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click