I need help with this code VB 2010 (Thanks)

romanos8

New member
Joined
Jul 15, 2011
Messages
3
Programming Experience
Beginner
Imports MySql.Data.MySqlClient
Imports System.Management
Imports System.Management.Instrumentation

Public Class welcome

Public bool2 As Boolean = True

Dim mysqlconnection As MySqlConnection
Dim mysqlconnection3 As MySqlConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bol As Boolean = True
Dim ds As New DataSet
mysqlconnection = New MySqlConnection
mysqlconnection.ConnectionString = "server=db4free.net;Port=3306; user id=user; password=password; database=database"
mysqlconnection.Open()

'##################################################################################
Dim sqlquiery = "SELECT ID, Reg, Rabljeno, Br FROM auto;"
Dim command As New MySqlCommand
Dim myadapter As New MySqlDataAdapter

Try
command.Connection = mysqlconnection
command.CommandText = sqlquiery
myadapter.SelectCommand = command
myadapter.Fill(ds, "baze3")
Catch ex As Exception
MsgBox("Error! You are not connected with database.", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Error")
End Try
'#################################################################################
Dim br As String = GetCPUId()
'##################################################################################

For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
If ds.Tables(0).Rows(i).Item(1).ToString = TextBox1.Text And ds.Tables(0).Rows(i).Item(2).ToString = "NE" Then
'###################################################################################
Dim sqlquiery1 = "UPDATE auto SET Rabljeno = 'DA' WHERE ID = '" & CInt(ds.Tables(0).Rows(i).Item(0).ToString) & "'"
Dim command1 As New MySqlCommand
Dim myadapter1 As New MySqlDataAdapter

Dim sqlquiery12 = "UPDATE auto SET Br = '" & br & "' WHERE ID = '" & CInt(ds.Tables(0).Rows(i).Item(0).ToString) & "'"
Dim command12 As New MySqlCommand
Dim myadapter12 As New MySqlDataAdapter

command1.Connection = mysqlconnection
command1.CommandText = sqlquiery1
myadapter1.SelectCommand = command1
command1.ExecuteNonQuery()

command12.Connection = mysqlconnection
command12.CommandText = sqlquiery12
myadapter12.SelectCommand = command12
command12.ExecuteNonQuery()

MsgBox("Thank you! Registration successful.")

System.IO.File.Create(Environ("SystemRoot") & "\Registration.ini")
bol = False
bool2 = False
traffic.Show()
Me.Hide()
'#################################################################################
End If
Next
If bol = True Then
MsgBox("Wrong registration number!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Error")
' Me.Close()
End If
mysqlconnection.Close()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'traffic.Show()
Me.Hide()
End Sub

Private Sub welcome_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IO.File.Exists(Environ("SystemRoot") & "\Registration.ini") Then
Me.WindowState = FormWindowState.Minimized
bool2 = False
traffic.Show()

Else
mysqlconnection3 = New MySqlConnection
mysqlconnection3.ConnectionString = "server=db4free.net;Port=3306; user id=user; password=password; database=database"
mysqlconnection3.Open()

Dim ds1 As New DataSet
'##################################################################################
Dim sqlquiery3 = "SELECT ID, Reg, Rabljeno, Br FROM auto;"
Dim command3 As New MySqlCommand
Dim myadapter3 As New MySqlDataAdapter

Try
command3.Connection = mysqlconnection3
command3.CommandText = sqlquiery3
myadapter3.SelectCommand = command3
myadapter3.Fill(ds1, "baze4")
Catch ex As Exception
MsgBox("Error! You are not connected with database.", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Error")
End Try
'#################################################################################
Dim br1 As String = GetCPUId()
'##################################################################################
For i As Integer = 0 To ds1.Tables(0).Rows.Count - 1
If ds1.Tables(0).Rows(i).Item(3).ToString <> br1 Then
Else
Me.WindowState = FormWindowState.Minimized
bool2 = False
'traffic.Show()
End If
Next
mysqlconnection3.Close()

End If
End Sub
'############################ CPU NUMBER ###################################
Public Function GetCPUId() As String
Dim cpuInfo As String = String.Empty
Dim temp As String = String.Empty
Dim mc As ManagementClass = _
New ManagementClass("Win32_Processor")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo As ManagementObject In moc
If cpuInfo = String.Empty Then
cpuInfo = _
mo.Properties("ProcessorId").Value.ToString()
End If
Next
Return cpuInfo
End Function
'###########################################################################

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Close()
End Sub
End Class

warnings:

CA2000 : Microsoft.Reliability : In method 'welcome.Button1_Click(Object, EventArgs)', object 'command1' is not disposed along all exception paths. Call System.IDisposable.Dispose on object 'command1' before all references to it are out of scope.
CA2000 : Microsoft.Reliability : In method 'welcome.Button1_Click(Object, EventArgs)', object 'command12' is not disposed along all exception paths. Call System.IDisposable.Dispose on object 'command12' before all references to it are out of scope.
CA2000 : Microsoft.Reliability : In method 'welcome.Button1_Click(Object, EventArgs)', call System.IDisposable.Dispose on object 'File.Create(Interaction.Environ("SystemRoot") & "\Registration.ini")' before all references to it are out of scope.
CA2000 : Microsoft.Reliability : In method 'welcome.Button1_Click(Object, EventArgs)', call System.IDisposable.Dispose on object 'command' before all references to it are out of scope.
CA2000 : Microsoft.Reliability : In method 'welcome.Button1_Click(Object, EventArgs)', call System.IDisposable.Dispose on object 'ds' before all references to it are out of scope.
CA2000 : Microsoft.Reliability : In method 'welcome.Button1_Click(Object, EventArgs)', call System.IDisposable.Dispose on object 'myadapter' before all references to it are out of scope.
CA2000 : Microsoft.Reliability : In method 'welcome.Button1_Click(Object, EventArgs)', call System.IDisposable.Dispose on object 'myadapter1' before all references to it are out of scope.
CA2000 : Microsoft.Reliability : In method 'welcome.Button1_Click(Object, EventArgs)', call System.IDisposable.Dispose on object 'myadapter12' before all references to it are out of scope.
CA2100 : Microsoft.Security : The query string passed to 'MySqlCommand.CommandText.Set(String)' in 'welcome.Button1_Click(Object, EventArgs)' could contain the following variables 'Conversions.ToString(Conversions.ToInteger(ds.Tables(0).Rows(i)(0).ToString()))'. If any of these variables could come from user input, consider using a stored procedure or a parameterized SQL query instead of building the query with string concatenations.
CA2100 : Microsoft.Security : The query string passed to 'MySqlCommand.CommandText.Set(String)' in 'welcome.Button1_Click(Object, EventArgs)' could contain the following variables 'Me.GetCPUId()', 'Conversions.ToString(Conversions.ToInteger(ds.Tables(0).Rows(i)(0).ToString()))'. If any of these variables could come from user input, consider using a stored procedure or a parameterized SQL query instead of building the query with string concatenations.
CA2000 : Microsoft.Reliability : In method 'welcome.GetCPUId()', call System.IDisposable.Dispose on object 'mc' before all references to it are out of scope.
CA2000 : Microsoft.Reliability : In method 'welcome.welcome_Load(Object, EventArgs)', call System.IDisposable.Dispose on object 'command3' before all references to it are out of scope.
CA2000 : Microsoft.Reliability : In method 'welcome.welcome_Load(Object, EventArgs)', call System.IDisposable.Dispose on object 'ds1' before all references to it are out of scope.
CA2000 : Microsoft.Reliability : In method 'welcome.welcome_Load(Object, EventArgs)', call System.IDisposable.Dispose on object 'myadapter3' before all references to it are out of scope.


Please help me.
 
You only need to declare one connection string.
In the class header part.

VB.NET:
    Public DC As SqlConnection = New SqlConnection("server=db4free.net;Port=3306; user id=user; password=password; database=database")
    Public DS As New DataSet
    Public SC As New SqlCommand
 
Back
Top