BP Forums
please Help Me Vb sign up with MySql.Data.MySqlClient - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8)
+---- Thread: please Help Me Vb sign up with MySql.Data.MySqlClient (/showthread.php?tid=518)



please Help Me Vb sign up with MySql.Data.MySqlClient - hohoswithcans - 04-19-2012

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 :
Code:
data2 = command2.ExecuteReader()
and it tells me my.Sqlexcption was unhandled the reson why is :
Code:
Field 'Name' doesn't have a default value:
the full code is here :
Code:
If Not TextBox6.Text = "puilia" Then
            MessageBoxEx.Show("Enter the Picture Box Right!", "Box", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            conn = New MySqlConnection("server=db4free.net;Port=3306; user id=code; password=code; database=code")
            Dim username As Boolean = True
            conn.Open()
            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
                    data.Close()
                Else


                    data.Close()
                    username = True
                End If

            End While
            data.Close()
            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()
                data.Close()

            End If
        End If
please help me i need this for my real program plz someone help me


Re: please Help Me Vb sign up with MySql.Data.MySqlClient - brandonio21 - 04-20-2012

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,
Code:
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.