Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB and MySQL help please
#1
hello, after a few year of in activeness in VB I'm back trying to make a program for myself to track some data, I followed along with the tutorial that on you tube, it seems to run ok with a couple exceptions. an 1 error that I have no clue how to fix or what it is.

first thing:
forgive me but I dont remember what it's called but if I click on the side bar to step by step the code on the While and the name is not in the database it bypassed the if statement, and if the name is in the database if pops up the msg box but if I hit it again I get an error Invalid attempt to read when reader is closed.

Second thing:
I get error MySqlException, on data2.command2.ExeciteReader
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Case, Powder, Bullet, Primer, Date, Comments)VALUES ('ert','ert','rt','et','erte' at line 1"

full Code below
Code:
Imports MySql.Data.MySqlClient

Public Class frmMain
    Public conn As MySqlConnection
    Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        Dim NAME As Boolean = True
        conn = New MySqlConnection("server=db4free.net;Port=3306;user id=PRIVATE;password=PRIVATE;database=PRIVATE")
        conn.Open()
        Dim sqlquery As String = "SELECT * FROM Reloads WHERE Name = '" & txtName.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
                MsgBox("Name Already in use!")
                NAME = False
                data.Close()
            Else
                data.Close()
                NAME = True
            End If
        End While
        data.Close()
        If NAME = True Then
            Dim sqlquery2 As String = "INSERT INTO Reloads (Name, Case, Powder, Bullet, Primer, Date, Comments)VALUES ('" & txtName.Text & "','" & txtCase.Text & "','" & txtPowder.Text & "','" & txtBullet.Text & "','" & txtPrimer.Text & "','" & txtDate.Text & "','" & txtComments.Text & "')"
            Dim data2 As MySqlDataReader
            Dim adapter2 As New MySqlDataAdapter
            Dim command2 As New MySqlCommand
            command2.CommandText = sqlquery2
            command2.Connection = conn
            adapter2.SelectCommand = command2
            data2 = command2.ExecuteReader
            MsgBox("Data Added")
        Else
            MsgBox("No Data Entered")
        End If
    End Sub
End Class


Messages In This Thread
VB and MySQL help please - by Chad1020 - 03-20-2012, 10:41 PM
Re: VB and MySQL help please - by Chad1020 - 03-21-2012, 12:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I read a link from mysql databse??? mnxford 9 31,124 04-12-2013, 06:27 PM
Last Post: brandonio21
  How do I use Listview to delete MySQL DB records kismetgerald 10 32,104 11-28-2012, 05:19 PM
Last Post: brandonio21
  [SOLVED] MySQL Update Query - What am I doing wrong? kismetgerald 11 40,552 10-18-2012, 07:16 PM
Last Post: brandonio21
  How do I fill my form with MySQL data based on Combobox? kismetgerald 8 25,325 10-14-2012, 09:05 PM
Last Post: brandonio21
  Help with creating an INSERT statement using MySQL kismetgerald 4 16,021 08-30-2012, 03:03 PM
Last Post: brandonio21
  MySQL Database Issue Moldraxian 7 27,845 08-13-2012, 08:58 PM
Last Post: brandonio21
  MySql Database Queries in VB.Net Moldraxian 6 21,112 07-26-2012, 03:44 PM
Last Post: Moldraxian
  How to Package MySql Connector and MySql Program? Moldraxian 3 14,056 07-20-2012, 12:23 PM
Last Post: brandonio21
  MySql Help Blackrobot 3 13,837 04-06-2012, 03:49 AM
Last Post: xolara
  MySQL Help -Kid- 6 23,825 02-20-2012, 11:57 AM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)