0

Here i am trying to register student's detail. and at the same time i want to retrieve a unique user id from connected SQL server and that's where i got stuck! I want to know what i am doing wrong here! Everything stored in the SQL server is correct and i have make an auto increment code in SQL! so why its not inserting and retrieving the data simultaneously

enter image description here

Imports MySql.Data.MySqlClient

Public Class Form3
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim con As New MySqlConnection("server=localhost;user id=root;password=root;persistsecurityinfo=True;database=bcaproject")
        Dim cmd As New MySqlCommand

        If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Then
         MessageBox.Show("Information shouldn't be empty...")
        Else
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "insert into student(F_name,L_name,Email,Phoneno,Username,Password) values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "')"
            cmd.ExecuteNonQuery()
            MessageBox.Show("successfully Registered")
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
            TextBox5.Text = ""
            TextBox6.Text = ""
            Form2.Show()
            Me.Hide()
        End If
    End Sub

    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Form2.Show()
        Me.Hide()
    End Sub

    Private Sub TextBox4_KeyPress1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
        If Asc(e.KeyChar) <> 8 Then
            If Not IsNumeric(e.KeyChar) Then
                tipvalidation.Show("Numeric input required", sender, 5000)
                e.KeyChar = Nothing
            End If
        End If
    End Sub
End Class
Teocci
  • 7,189
  • 1
  • 50
  • 48
Shivani
  • 1
  • 2

0 Answers0