Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
please Help Me Vb sign up with MySql.Data.MySqlClient
please Help Me Vb this error on vb every time i launch the program and this is a sign in/ signup program
any when i sign up to my program this error it highlights
this :
data2 = command2.ExecuteReader()
and it tells me my.Sqlexcption was unhandled the reson why is :
Field 'Name' doesn't have a default value:
the full code is here :
If Not TextBox6.Text = "puilia" Then
            MessageBoxEx.Show("Enter the Picture Box Right!", "Box", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            conn = New MySqlConnection(";Port=3306; user id=code; password=code; database=code")
            Dim username As Boolean = True
            Dim sqlquery As String = "SELECT * FROM code DB WHERE Username = '" & TextBox1.Text & "';"
            Dim data As MySqlDataReader
            Dim adapter As New MySqlDataAdapter
            Dim command As New MySqlCommand
            command.CommandText = sqlquery
            command.Connection = conn
            adapter.SelectCommand = command
            data = command.ExecuteReader
            While data.Read()
                If data.HasRows() = True Then
                    MessageBoxEx.Show("Username Is In Use", "Username", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    username = False

                    username = True
                End If

            End While
            If username = True Then
                Dim sqlquery2 As String = "INSERT INTO code (Username, Password)VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "')"
                Dim data2 As MySqlDataReader
                Dim command2 As New MySqlCommand
                command2.CommandText = sqlquery2
                command2.Connection = conn
                adapter.SelectCommand = command2
                data2 = command2.ExecuteReader()

            End If
        End If
please help me i need this for my real program plz someone help me
Well, the problem is not with your VB.NET code, but actually lies within your MySQL database itself. When you update the table code with this line,
Dim sqlquery2 As String = "INSERT INTO code (Username, Password)VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "')"

You do not specify a value for the "Name" field in your database table. And your name field does not know what to do if a value is not specified, so it throws you this error. There are two main ways to solve this.
Option 1. When you make your INSERT code call, specify a value for the Name field
Option 2. Set a default value for the name field in your DB4FREE Settings.
My Blog | My Setup | My Videos | Have a wonderful day.

Possibly Related Threads...
Thread Author Replies Views Last Post
  MySQL / Wamp Server Issues jaminben 2 2,356 04-22-2012, 10:31 AM
Last Post: brandonio21
  connect to mysql client cry1978 2 1,867 07-12-2011, 11:09 AM
Last Post: brandonio21
  MySQL Module xolara 4 2,627 04-16-2011, 12:28 AM
Last Post: xolara

Forum Jump:

Users browsing this thread: 1 Guest(s)