I'm getting an error when I put the command.ExecuteNonQuery()
but when I remove the code it says
register done
but it is not inserting anything into the database.
Try
If TextBox1.Text = Nothing Or TextBox2.Text = Nothing Or TextBox3.Text = Nothing Or TextBox4.Text = Nothing Or TextBox5.Text = Nothing Or TextBox6.Text = Nothing Or TextBox7.Text = Nothing Or TextBox8.Text = Nothing Or ComboBox1.Text = Nothing Then
MsgBox("please complete the fields!", MsgBoxStyle.Critical)
Else
MysqlConn.Open()
command.Connection = MysqlConn
command.CommandType = CommandType.Text
command.CommandText = "SELECT * FROM customer WHERE email = @email"
READER = command.ExecuteReader
If READER.HasRows Then
MsgBox("e-mail is already in use!", MsgBoxStyle.Critical)
MysqlConn.Close()
Else
If Not READER.IsClosed Then
READER.Close()
End If
command.Connection = MysqlConn
command.CommandType = CommandType.Text
command.CommandText = "INSERT INTO customer (`username`, `firstname`, `lastname`, `password`, `confirmpass`, `securityq`, `securitya`, `gender`, `email`, `contactno`) VALUES (@uname,@fname,@lname,@pword,@confirm,@secuq,@secuqa,@gender,@email,@contactno)"
With command.Parameters
.AddWithValue("@uname", TextBox1.Text)
.AddWithValue("@fname", TextBox2.Text)
.AddWithValue("@lname", TextBox3.Text)
.AddWithValue("@pword", TextBox4.Text)
.AddWithValue("@confirm", TextBox5.Text)
.AddWithValue("@secuq", ComboBox1.SelectedItem)
.AddWithValue("@secuqa", TextBox6.Text)
If RadioButton1.Checked Then
.AddWithValue("@gender", "male")
ElseIf RadioButton2.Checked Then
.AddWithValue("@gender", "female")
End If
.AddWithValue("@email", TextBox7.Text)
.AddWithValue("@contactno", TextBox8.Text)
End With
command.ExecuteNonQuery()
MsgBox("Registration done!", MsgBoxStyle.OkOnly)
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
RadioButton1.Checked = False
RadioButton2.Checked = False
TextBox7.Clear()
TextBox8.Clear()
ComboBox1.ResetText()
Form1.Show()
Hide()
MysqlConn.Close()
End If
End If
Catch ex As mysqlException
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try