MySqlConnection is not defined - mysql

Im new in vb.net and mysql.
I got confused when I am defining Dim SQLConnection As MySqlConnection = New MySqlConnection.
And it said that the New "MySqlConnection" is not defined but I made sure that I have imported namespace needed or anything but i still have an error and i cant figure out whats the problem.
This is my code:
Imports MySql.Data.MySqlClient
Public Class EditInfo
Dim bednumber As String = ""
Dim patient_name As String = ""
Dim patient_age As String = ""
Dim date_of_confinement As String = ""
Dim type_of_sickness As String = ""
Dim type_of_IV_fluid As String = ""
Dim number_of_bottles As String = ""
Dim drop_rate As String = ""
Dim ServerString As String = "Server=localhost; database=patientinfo;user id=root;password=root" 'connection to phpmyadmin database
Dim SQLConnection As MySqlConnection = New MySqlConnection
Private Sub PatientInfoBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PatientInfoBindingNavigatorSaveItem.Click
Me.Validate()
Me.PatientInfoBindingSource.EndEdit()
Me.PatientInfoTableAdapter.Update(Me.PatientInfoDBDataSet.PatientInfo)
End Sub
Any help would be appreciated. Thanks! I got confused sorry XD

Try:
Replace
Dim SQLConnection As MySqlConnection = New MySqlConnection
by
Dim SQLConnection As New MySqlConnection()
Other point, you may use String.Empty to set value for String instead of "".
HTH.

Related

VB.net 'System.Collections.Generic.KeyNotFoundException' exception

Here is my code:
Imports System.IO
Imports MySql.Data.MySqlClient
Public Class F_login
Dim strServer As String = "localhost"
Dim strDB As String = "lab_utilization"
Dim strUser As String = "root"
Dim strPw As String = ""
Dim cs As String = "Server=$($strServer);Port=3306;Database=$($strDB);Uid=$($strUser);Pwd=$($strPw);"
Dim con As New MySqlConnection(cs)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim id As Integer = uid.Text
Dim pswd As New MySqlCommand("Select Password from authentication where id = " & id & "", con)
pswd.ExecuteNonQuery()
Dim mysqladapter As New MySqlDataAdapter(pswd)
Dim dt As New DataTable
mysqladapter.Fill(dt)
dg.DataSource = dt
Dim psd As String = dg.Rows(0).Cells(0).Value
If pswd1.Text = psd Then
Me.Visible = False
F_Main_screen.Show()
Else
MessageBox.Show("Invalid ID or Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Private Sub F_login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
con.ConnectionString = cs
con.Open()
End Sub
End Class
The following exception occurs on con.Open():
An unhandled exception of type System.Collections.Generic.KeyNotFoundException' occurred in MySql.Data.dll
Additional information: Keyword 'address' not found.
Any assistance will be appreciated, thank you.
I don't think your syntax for string interpolation is correct.
Try changing your connection string to:
`Dim cs As String = "Server=${strServer};Port=3306;Database=${strDB};Uid=${strUser};Pwd=${strPw};"

Reference required to assembly 'System.Data.Common', containing the type 'DBConnection'

I'm making a program in VB with MySQL. For some reason, I got an error where all of my references had a yellow triangle, but I have since fixed that by reinstalling them on NuGet. Now I have 39 errors which I didn't have before, and I haven't edited the code since then.
Here are the errors:
errors
That isn't all of the errors, but the rest are a lot of duplicates. Now here's my form1 code.
Imports MaterialSkin
Imports MySql.Data.MySqlClient
Imports System.Net
Imports System.Text
Imports System.Data
Public Class Form1
Private Sub LoginBtn_Click(sender As Object, e As EventArgs) Handles LoginBtn.Click
Dim address As String
address = "http://ipv4bot.whatismyipaddress.com"
Dim client As WebClient = New WebClient()
Dim reply As String = client.DownloadString(address)
Dim connString As String = "Database=aquarius;Data Source=localhost;User Id=root;Password=asd"
Dim conn As New MySqlConnection(connString)
Dim Query As String
Dim Query2 As String
Dim reader As MySqlDataReader
Try
conn.Open()
Query = "SELECT * FROM login WHERE username = ?UserName AND password = ?Password AND buyer = ?Buyer"
Dim cmd As New MySqlCommand(Query, conn)
cmd.Parameters.Add(New MySqlParameter("?UserName", MaterialSingleLineTextField1.Text))
cmd.Parameters.Add(New MySqlParameter("?Password", MaterialSingleLineTextField2.Text))
cmd.Parameters.Add(New MySqlParameter("?Buyer", "true"))
cmd.Connection = conn
reader = cmd.ExecuteReader
If reader.HasRows() Then
conn.Close()
MessageBox.Show("Thanks for buying Aquarius", "Welcome")
conn.Open()
Query2 = "INSERT INTO logs (ip, user, time) VALUES (?Ip, ?User, ?Time)"
Dim cmd2 As New MySqlCommand(Query2, conn)
cmd2.Parameters.Add(New MySqlParameter("?Ip", reply.ToString))
cmd2.Parameters.Add(New MySqlParameter("?User", Environment.UserName))
cmd2.Parameters.Add(New MySqlParameter("?Time", System.DateTime.Now.ToString()))
cmd2.ExecuteNonQuery()
conn.Close()
Form2.Show()
Me.Close()
Else
MessageBox.Show("Your password is incorrect or you are not whitelisted.", "Sad")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error")
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim SkinManager As MaterialSkinManager = MaterialSkinManager.Instance
SkinManager.AddFormToManage(Me)
SkinManager.Theme = MaterialSkinManager.Themes.DARK
SkinManager.ColorScheme = New ColorScheme(Primary.LightBlue500, Primary.LightBlue600, Primary.LightBlue700, Accent.LightBlue200, TextShade.WHITE)
End Sub
Private Sub MaterialRaisedButton1_Click(sender As Object, e As EventArgs) Handles MaterialRaisedButton1.Click
Dim connString As String = "Database=aquarius;Data Source=localhost;User Id=root;Password=asd"
Dim conn As New MySqlConnection(connString)
Dim Query As String
Try
conn.Open()
Query = "INSERT INTO login (username, password, buyer) VALUES (?UserName, ?Password, ?Buyer)"
Dim cmd As New MySqlCommand(Query, conn)
cmd.Parameters.Add(New MySqlParameter("?UserName", MaterialSingleLineTextField1.Text))
cmd.Parameters.Add(New MySqlParameter("?Password", MaterialSingleLineTextField2.Text))
cmd.Parameters.Add(New MySqlParameter("?Buyer", "false"))
cmd.Connection = conn
cmd.ExecuteNonQuery()
conn.Close()
MessageBox.Show("Done!", ":)")
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error")
End Try
End Sub
End Class

I am always getting fingerprint not verified

Anytime I scan a fingerprint for verification I get the message "Fingerprint not verified" even though I have already enrolled that fingerprint into the database. Here is the code for capture when the form loads
Here is the code for capture when the form loads
Private Sub Me_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Init()
StartCapture()
Dim conn As New MySqlConnection
Dim cmd As New MySqlCommand
Dim sql As String
conn.ConnectionString = "**** "
conn.Open()
sql = ("SELECT * FROM new_case_file")
cmd.Connection = conn
cmd.CommandText = sql
Dim rdr As MySqlDataReader = cmd.ExecuteReader()
While (rdr.Read())
Dim MemStream As IO.MemoryStream
Dim fpBytes As Byte()
fpBytes = rdr("FingerPrint")
MemStream = New IO.MemoryStream(fpBytes)
Dim templa8 As DPFP.Template = New DPFP.Template()
templa8.DeSerialize(MemStream)
Dim serializedTemplate As Byte() = MemStream.ToArray
Dim tmpObj As New AppData
Dim FPList As List(Of AppData) = New List(Of AppData)
'tmpObj.No = rdr("No").ToString()
'tmpObj.Template = templa8
'FPList.Add(tmpObj)
End While
conn.Close()
End Sub
Here is the code for verification. When l click on the button it should verify, because l called the sub verifyControl_Commplete in the button click sub.
Private Sub verifyControl_OnComplete(ByVal Control As Object, ByVal FeatureSet As DPFP.FeatureSet, ByRef EventHandlerStatus As
DPFP.Gui.EventHandlerStatus) Handles verifyControl.OnComplete
Dim printFound As Boolean = False
'Dim printFound As Boolean = True
'Dim printFound As Boolean = False
Dim VerifiedFPData = New AppData
Dim FPList As List(Of AppData) = New List(Of AppData)
Try
For Each FPData As AppData In FPList
Dim tmplateData As New DPFP.Template
'tmplateData = FPData.Template
Dim compareTo As New DPFP.FeatureSet
compareTo = FeatureSet
Dim ver As New DPFP.Verification.Verification()
Dim res As New DPFP.Verification.Verification.Result()
If Not tmplateData Is Nothing Then
ver.Verify(FeatureSet, tmplateData, res)
If res.Verified Then
EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Success
printFound = True
VerifiedFPData = FPData
Exit For
End If
End If
Next
Catch ex As Exception
MessageBox.Show("Error")
End Try
If printFound Then
MsgBox("Verified")
Else
EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Failure
MsgBox("Not Verified")
End If
End Sub
Private Sub btnverifyfp_Click(sender As Object, e As EventArgs) Handles btnverifyfp.Click
verifyControl_OnComplete(Nothing, Nothing, Nothing)
End Sub
This is the code l used in saving the fingerprint
Dim fingerprintData As MemoryStream = New MemoryStream
Enroller.Template.Serialize(fingerprintData)
Dim serializedTemplate As Byte() = fingerprintData.ToArray()
Dim bytes() As Byte = serializedTemplate
Try this:
'THIS NEEDS TO BE AT THE CLASS-LEVEL, AS A MEMBER
Private FPList As New List(Of AppData)
Private Sub Me_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs)
Handles MyBase.Load
Init()
StartCapture()
Dim sql As String = "SELECT * FROM new_case_file"
Using conn As New MySqlConnection("**** "), _
cmd As New MySqlCommand(sql, conn)
conn.Open()
Using rdr As MySqlDataReader = cmd.ExecuteReader()
FPList.Clear()
While (rdr.Read())
Dim tmpObj As New AppData
tmpObj.No = rdr("No").ToString()
Dim fpBytes As Byte() = rdr("FingerPrint")
Using MemStream As New IO.MemoryStream(fpBytes)
Dim templa8 As New DPFP.Template()
templa8.DeSerialize(MemStream)
End Using
tmpObj.Template = templa8
FPList.Add(tmpObj)
End While
rdr.Close()
End Using
End Using
End Sub
And now other code later can use that same FPList variable. If you find yourself writing New List(Of AppData) anywhere else, you're doing something wrong.
The AppData class should look something like this:
Public Class AppData
Public Property No As String
Public Property Template As DFFP.Template
End Class
And finally, the verify code:
Private Sub verifyControl_OnComplete(ByVal Control As Object, ByVal FeatureSet As DPFP.FeatureSet,
ByRef EventHandlerStatus As DPFP.Gui.EventHandlerStatus)
Handles verifyControl.OnComplete
Try
Dim ver As New DPFP.Verification.Verification()
Dim res As New DPFP.Verification.Verification.Result()
For Each FPData As AppData In FPList
If FPData.Template Is Nothing Then Continue
ver.Verify(FeatureSet, FPData.Template, res)
If res.Verified Then
EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Success
MsgBox("Verified")
Return
End If
Next FPDAta
Catch ex As Exception
MessageBox.Show("Error")
End Try
EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Failure
MsgBox("Not Verified")
End Sub
Again... we don't have access to your API documentation, test data, or equipment. That means we're blind trying to help you here. There's probably some things wrong with this, and you'll have to be able to troubleshoot and debug.

Too many arguments to 'Public Sub New() VB .NET

I use MySqlBackup.NET_2.0.9.2 to backup a MySQL database.
I use this code:
Private Sub cmdExportBazaDate_Click(sender As System.Object, e As System.EventArgs) Handles cmdExportBazaDate.Click
Dim constring As String = Parametriiconexiune
Dim zi As String = data
Dim file As String = cale_salvari + data + "_baza" + ".sql"
Dim conn As MySqlConnection
conn = New MySqlConnection(constring)
Dim cmd As MySqlCommand
cmd = New MySqlCommand
cmd.Connection = conn
conn.Open()
Dim mb As MySqlBackup
mb = New MySqlBackup(cmd)
mb.ExportToFile(file)
conn.Close()
End Sub
I get the error:
Too many arguments to 'Public Sub New()'
For this line:
mb = New MySqlBackup(cmd)
How to fix please to bypass the error.

how to avoid error: "CommandText property has not been initialized properly"?

database is in the sqlYog,
when i run this program i am getting the error:
CommandText property has not been initialized properly..?
please help me
Imports MySql.Data.MySqlClient
Imports System.Data
Partial Class login
Inherits System.Web.UI.Page
Public dbconn As New MySqlConnection
Public sql As String
Public dbcomm As New MySqlCommand
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
dbconn = New MySqlConnection("data source= localhost; user id=root; password=search; database=bookstore;")
dbconn.Open()
dbcomm.Connection = dbconn
End Sub
Protected Sub btn_login_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_login.Click
Try
dbcomm = New MySqlCommand(sql, dbconn)
sql = "select * from bookstore.lib_user where username=#username and password=#password"
dbcomm.Parameters.AddWithValue("#username", txt_username.Text)
dbcomm.Parameters.AddWithValue("#password", txt_password.Text)
Dim dbadpt As New MySqlDataAdapter(dbcomm)
Dim dt As New DataTable()
dbadpt.Fill(dt)
If dt.Rows.Count > 0 Then
MsgBox("login is suceesfull")
Else
Literal1.Text = "invalid login"
End If
Catch ex As Exception
MsgBox("read this error: " + ex.Message)
End Try
End Sub
End Class
Please change the sequence of lines.
First set the query text then call the command constructor.
sql = "select * from bookstore.lib_user where username=#username and password=#password"
dbcomm = New MySqlCommand(sql, dbconn)
As per your code sql is empty when assigning to your MySqlCommand, You need to set the sql value first then assign it to your MySqlCommand object .
sql = "select * from bookstore.lib_user where username=#username and password=#password"
dbcomm = New MySqlCommand(sql, dbconn)