Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB and MySQL help please
#3
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")

            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
            conn.Open()
            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()
            conn.close()
            If NAME = True Then
                Dim sqlquery2 As String = "INSERT INTO reloads (name) VALUES(1)"
                MsgBox(sqlquery2)

                Dim data2 As MySqlDataReader
                Dim adapter2 As New MySqlDataAdapter
                Dim command2 As New MySqlCommand
                command2.CommandText = sqlquery2
                command2.Connection = conn
                conn.open()
                adapter2.SelectCommand = command2
                data2 = command2.ExecuteReader
                MsgBox("Data Added")
                conn.close()
            Else
                MsgBox("No Data Entered")
            End If
        End Sub
    End Class

Try closing and opening your connection before you execute new pieces of code. I have inserted these segments into your code if you simply want to copy paste.
My Blog | My Setup | My Videos | Have a wonderful day.


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
Re: VB and MySQL help please - by brandonio21_phpbb3_import2 - 03-21-2012, 04:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I read a link from mysql databse??? mnxford 9 33,029 04-12-2013, 06:27 PM
Last Post: brandonio21
  How do I use Listview to delete MySQL DB records kismetgerald 10 33,855 11-28-2012, 05:19 PM
Last Post: brandonio21
  [SOLVED] MySQL Update Query - What am I doing wrong? kismetgerald 11 43,302 10-18-2012, 07:16 PM
Last Post: brandonio21
  How do I fill my form with MySQL data based on Combobox? kismetgerald 8 26,704 10-14-2012, 09:05 PM
Last Post: brandonio21
  Help with creating an INSERT statement using MySQL kismetgerald 4 16,752 08-30-2012, 03:03 PM
Last Post: brandonio21
  MySQL Database Issue Moldraxian 7 29,044 08-13-2012, 08:58 PM
Last Post: brandonio21
  MySql Database Queries in VB.Net Moldraxian 6 22,376 07-26-2012, 03:44 PM
Last Post: Moldraxian
  How to Package MySql Connector and MySql Program? Moldraxian 3 14,754 07-20-2012, 12:23 PM
Last Post: brandonio21
  MySql Help Blackrobot 3 14,615 04-06-2012, 03:49 AM
Last Post: xolara
  MySQL Help -Kid- 6 25,398 02-20-2012, 11:57 AM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)