03-21-2012, 12:28 AM
update,
have not fixed first problem but I can get the code to post with a single database entry but if I try multiple I get the original error.
have not fixed first problem but I can get the code to post with a single database entry but if I try multiple I get the original error.
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) VALUES(1)"
MsgBox(sqlquery2)
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