Textbox data Output - vb.net

Good day im having some trouble with my code
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Tab Then
checkoperator()
TextBox1.Text = ""
SendKeys.Send("{BACKSPACE}")
If lbloperatorb.Text = "" Then
TextBox1.Text = ""
MsgBox("User ID does not exist.")
lbloperatorb.Text = ""
TextBox1.Focus()
Else
TextBox1.Text = lbloperatorb.Text
TextBox1.Enabled = False
End If
cmbmodel1.Focus()
End If
End Sub
Public Sub checkoperator()
Dim cmd As New MySqlCommand
cmd.Connection = conn
cmd.CommandText = "SELECT empname FROM tbluser where userid= '" + TextBox1.Text + "'"
lbloperatorb.Text = cmd.ExecuteScalar
End Sub
When im using tab as my "ENTER" and pasting query at my text box here's what i got
i already tried to delete the textbox before sending data. but nothing happen

Instead of the KeyDown, use the Leave event. The following code will then work.
Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
checkoperator()
'TextBox1.Text = ""
'SendKeys.Send("{BACKSPACE}")
If lbloperatorb.Text = "" Then
TextBox1.Text = ""
MsgBox("User ID does not exist.")
lbloperatorb.Text = ""
TextBox1.Focus()
Else
TextBox1.Text = lbloperatorb.Text
TextBox1.Enabled = False
lbloperatorb.Text = ""
End If
'lbloperatorb.Focus()
End Sub

Related

solution Index was out of range. Must be non-negative and less than the size of the collection in vb.net

I have an error problem "Index was out of range. Must be non-negative and less than the size of the collection" when I input a value with the value of the number "1" then an error appears and the value is not in the "code" column in the datagridview. Is there a best recommendation?
Public x As Integer
Dim source1 As New BindingSource()
Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles TextBox2.KeyDown
If e.KeyCode = Keys.Back Then
source1.Filter = ""
TextBox1.Clear()
Else
If e.KeyCode = Keys.Enter Then
source1.Filter = "CODE = '" & Replace(TextBox2.Text, "'", "") & "'"
x = DataGridView1.Rows.IndexOf(DataGridView1.CurrentRow)
txtCODE.Text = DataGridView1.Rows(x).Cells(0).Value.ToString()
Dim dte = DataGridView1.Rows(x).Cells(1).Value.ToString()
If dte <> Nothing Then
txtDTE.Text = CDate(dte)
Else
'CLEAR txtDTE if dt <> nothing
txtDTE.Clear()
End If
txtQTY.Text = DataGridView1.Rows(x).Cells(2).Value.ToString()
txtPRICE.Text = DataGridView1.Rows(x).Cells(3).Value.ToString()
txtPRICE.Text = String.Format(System.Globalization.CultureInfo.GetCultureInfo("en-US"), "{0:N0}", Double.Parse(txtPRICE.Text))
If source1.Count <= 0 Then
source1.Filter = ""
TextBox2.Clear()
MsgBox("No Result Found!", MsgBoxStyle.Exclamation)
End If
End If
End If
End Sub
I fixed it by adding a check to make sure that the index of the current row is valid.
Public x As Integer
Dim source1 As New BindingSource()
Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles TextBox2.KeyDown
If e.KeyCode = Keys.Back Then
source1.Filter = ""
TextBox1.Clear()
Else
If e.KeyCode = Keys.Enter Then
source1.Filter = "CODE = '" & Replace(TextBox2.Text, "'", "") & "'"
x = DataGridView1.Rows.IndexOf(DataGridView1.CurrentRow)
***If x >= 0 And x <= DataGridView1.Rows.Count - 1 Then*** 'ADD THIS CODE SOLUTION FOR ME
txtCODE.Text = DataGridView1.Rows(x).Cells(0).Value.ToString()
Dim dte = DataGridView1.Rows(x).Cells(1).Value.ToString()
If dte <> Nothing Then
txtDTE.Text = CDate(dte)
Else
'CLEAR txtDTE if dt <> nothing
txtDTE.Clear()
End If
txtQTY.Text = DataGridView1.Rows(x).Cells(2).Value.ToString()
txtPRICE.Text = DataGridView1.Rows(x).Cells(3).Value.ToString()
txtPRICE.Text = String.Format(System.Globalization.CultureInfo.GetCultureInfo("en-US"), "{0:N0}", Double.Parse(txtPRICE.Text))
End If
End If
End If
If source1.Count <= 0 Then
source1.Filter = ""
TextBox2.Clear()
MsgBox("No Result Found!", MsgBoxStyle.Exclamation)
End If
End Sub

wants events in textbox with MessageBox and not gridview filter state if code is not found in vb.net

I want to appear MessageBox and not gridview filter state if code is not found.
Dim source1 As New BindingSource()
Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles TextBox2.KeyDown
If TextBox2.Text = "" Then
source1.Filter = ""
Me.DataGridView1.Refresh()
Else
If e.KeyCode = Keys.Enter Then
source1.Filter = "CODE like '' + '" & TextBox2.Text & "' + '' "
Me.DataGridView1.Refresh()
End If
End If
End Sub
Add another if statement inside the else then check if the source1 has rows, if rows <= 0 then clear the filter and the textbox.
UPDATED
Dim source1 As New BindingSource()
Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles TextBox2.KeyDown
If TextBox2.Text = "" Then
source1.Filter = ""
Me.DataGridView1.Refresh()
Else
If e.KeyCode = Keys.Enter Then
source1.Filter = "CODE like '' + '" & TextBox2.Text & "' + '' "
' If Else Statement to determine the count of your bindingsource
' Check the results, if result is less than or equal to 0
' then prompt messagebox and clear the source filter
If source1.count <= 0
source1.Filter = ""
TextBox2.Clear()
MsgBox("No Result Found!", MsgBoxStyle.Exclamation)
End If
Me.DataGridView1.Refresh()
End If
End If
End Sub

Update Database and datagridview from textboxes

I have an application with a datagridview on the bottom half of the page and textboxes, combo-boxes, buttons, etc... on the top half.
When the user changes the highlighted row in the grid then it displays all of the information for that row in the objects on the top half.
If user wants to change the data in a row then he clicks an edit button which enables the textboxes etc... and allows the user to edit the data.
(All of the above works fine).
When he wants to save the changes then he clicks the save button.
This should update the datasource to the grid and show the changes in the grid.
However, I have been unable to get it do this.
Any Help appreciated.
Code below:
Imports System.Data.SqlClient
Public Class frmEmployeeInformation
Public SQL As New SQLControl()
Dim strEditType As String
Private Sub frmEmployeeInformation_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LoadGrid()
End Sub
Public Sub LoadGrid(Optional query As String = "")
If query = "" Then
SQL.ExecuteQuery("Select * from EmployeeInformation;")
Else
SQL.ExecuteQuery(query)
End If
If SQL.HasException(True) Then Exit Sub
dgvEmployeeInformation.DataSource = SQL.DBDS.Tables(0)
dgvEmployeeInformation.Rows(0).Selected = True
SQL.DBDA.UpdateCommand = New SqlClient.SqlCommandBuilder(SQL.DBDA).GetUpdateCommand
End Sub
Private Sub DisplayValues()
If dgvEmployeeInformation.RowCount > 2 Then
If dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("FirstName").Value <> Nothing Then
txtFirstName.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("FirstName").Value.ToString 'EmployeeInformation.FirstName
End If
If dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("LastName").Value <> Nothing Then
txtLastName.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("LastName").Value.ToString 'EmployeeInformation.LastName
End If
If dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("SSN").Value IsNot Nothing Then
txtSSN.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("SSN").Value.ToString 'EmployeeInformation.SSN
End If
If dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("EmployeeInformationID").Value <> Nothing Then
txtEmployeeID.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("EmployeeInformationID").Value.ToString 'EmployeeInformation.EmployeeInformationID
End If
'If dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("ADPID").Value <> Nothing Then
'txtADPID.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("ADPID").Value.ToString 'EmployeeInformation.ADPID
'End If
'If dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("VP").Value <> Nothing Then
'cboVP.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("VP").Value.ToString 'EmployeeInformation.VP
'End If
If dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("Default_LocationID").Value <> Nothing Then
cboDefaultLocation.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("Default_LocationID").Value.ToString 'EmployeeInformation.DefaultLocation
End If
If dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("SystemTableID").Value <> Nothing Then
txtTableID.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("SystemTableID").Value.ToString 'EmployeeInformation.TableID
End If
If dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("EmployeeActive").Value <> Nothing Then
chkbxActive.Checked = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("EmployeeActive").Value.ToString 'EmployeeInformation.EmployeeActive
End If
If dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("PrimaryFile").Value <> Nothing Then
chkbxPrimaryFile.Checked = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("PrimaryFile").Value.ToString 'EmployeeInformation.PrimaryFile
End If
If dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("UnallocatedTime").Value <> Nothing Then
chkbxUnallocatedTime.Checked = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("UnallocatedTime").Value.ToString 'EmployeeInformation.UnallocatedTime
End If
End If
End Sub
Private Sub ChangeButtons()
btnClose.Enabled = Not btnClose.Enabled
btnSave.Enabled = Not btnSave.Enabled
btnClear.Enabled = Not btnClear.Enabled
btnFind.Enabled = Not btnFind.Enabled
btnCancel.Enabled = Not btnCancel.Enabled
btnEdit.Enabled = Not btnEdit.Enabled
btnAdd.Enabled = Not btnAdd.Enabled
btnCopy.Enabled = Not btnCopy.Enabled
End Sub
Private Sub ChangeFields()
chkbxActive.Enabled = Not chkbxActive.Enabled
chkbxPrimaryFile.Enabled = Not chkbxPrimaryFile.Enabled
chkbxUnallocatedTime.Enabled = Not chkbxUnallocatedTime.Enabled
txtTableID.Enabled = Not txtTableID.Enabled
txtADPID.Enabled = Not txtADPID.Enabled
cboVP.Enabled = Not cboVP.Enabled
cboDefaultLocation.Enabled = Not cboDefaultLocation.Enabled
End Sub
Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub btnFind_Click(sender As Object, e As EventArgs) Handles btnFind.Click
If txtEmployeeID.Text <> "" Then
SQL.AddParam("#EmployeeInformationID", txtEmployeeID.Text)
LoadGrid("select * from EmployeeInformation where EmployeeInformationID = #EmployeeInformationID;")
ElseIf txtSSN.Text <> "" Then
SQL.AddParam("#SSN", txtSSN.Text)
LoadGrid("select * from EmployeeInformation where SSN = #SSN;")
ElseIf txtFirstName.Text <> "" And txtLastName.Text <> "" Then
SQL.AddParam("#FirstName", txtFirstName.Text)
SQL.AddParam("#LastName", txtLastName.Text)
LoadGrid("select * from EmployeeInformation where FirstName = #FirstName and LastName = #LastName;")
Else
LoadGrid("Select * from EmployeeInformation;")
End If
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
txtFirstName.Text = ""
txtLastName.Text = ""
txtSSN.Text = ""
txtEmployeeID.Text = ""
txtADPID.Text = ""
cboVP.Text = ""
cboDefaultLocation.Text = ""
txtTableID.Text = ""
chkbxActive.Checked = "False"
chkbxPrimaryFile.Checked = "False"
chkbxUnallocatedTime.Checked = "False"
End Sub
Private Sub dgvEmployeeInformation_DoubleClick(sender As Object, e As EventArgs) Handles dgvEmployeeInformation.DoubleClick
DisplayValues()
ChangeFields()
ChangeButtons()
End Sub
Private Sub dgvEmployeeInformation_SelectionChanged(sender As Object, e As EventArgs) Handles dgvEmployeeInformation.SelectionChanged
DisplayValues()
End Sub
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
If strEditType = "Edit" Then
' The code below updates the grid but the changes are not saved to the database. Probably not the way to go
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("FirstName").Value = txtFirstName.Text 'EmployeeInformation.FirstName
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("LastName").Value = txtLastName.Text 'EmployeeInformation.LastName
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("SSN").Value = txtSSN.Text 'EmployeeInformation.SSN
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("EmployeeInformationID").Value = txtEmployeeID.Text 'EmployeeInformation.EmployeeInformationID
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("Default_LocationID").Value = cboDefaultLocation.Text 'EmployeeInformation.DefaultLocation
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("SystemTableID").Value = txtTableID.Text 'EmployeeInformation.TableID
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("EmployeeActive").Value = chkbxActive.Checked 'EmployeeInformation.EmployeeActive
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("PrimaryFile").Value = chkbxPrimaryFile.Checked 'EmployeeInformation.PrimaryFile
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("UnallocatedTime").Value = chkbxUnallocatedTime.Checked 'EmployeeInformation.UnallocatedTime
' The code above updates the grid but the changes are not saved to the database.
dgvEmployeeInformation.EndEdit()
SQL.DBDS.Tables(0).AcceptChanges()
SQL.DBDA.Update(SQL.DBDS)
'txtADPID.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("ADPID").Value.ToString 'EmployeeInformation.ADPID
'cboVP.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("VP").Value.ToString 'EmployeeInformation.VP
End If
ChangeFields()
ChangeButtons()
strEditType = ""
'LoadGrid()
End Sub
Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
ChangeFields()
ChangeButtons()
strEditType = ""
End Sub
Private Sub btnEdit_Click(sender As Object, e As EventArgs) Handles btnEdit.Click
dgvEmployeeInformation_DoubleClick(Nothing, EventArgs.Empty)
strEditType = "Edit"
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
btnClear_Click(Nothing, EventArgs.Empty)
txtFirstName.Focus()
strEditType = "Add"
ChangeFields()
ChangeButtons()
End Sub
Private Sub btnCopy_Click(sender As Object, e As EventArgs) Handles btnCopy.Click
cboDefaultLocation.Focus()
strEditType = "Copy"
ChangeFields()
ChangeButtons()
End Sub
End Class
TRY ANOTHER WAY!!
I suggest you, instead of doing this:
If strEditType = "Edit" Then
' The code below updates the grid but the changes are not saved to the database. Probably not the way to go
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("FirstName").Value = txtFirstName.Text 'EmployeeInformation.FirstName
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("LastName").Value = txtLastName.Text 'EmployeeInformation.LastName
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("SSN").Value = txtSSN.Text 'EmployeeInformation.SSN
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("EmployeeInformationID").Value = txtEmployeeID.Text 'EmployeeInformation.EmployeeInformationID
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("Default_LocationID").Value = cboDefaultLocation.Text 'EmployeeInformation.DefaultLocation
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("SystemTableID").Value = txtTableID.Text 'EmployeeInformation.TableID
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("EmployeeActive").Value = chkbxActive.Checked 'EmployeeInformation.EmployeeActive
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("PrimaryFile").Value = chkbxPrimaryFile.Checked 'EmployeeInformation.PrimaryFile
dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("UnallocatedTime").Value = chkbxUnallocatedTime.Checked 'EmployeeInformation.UnallocatedTime
' The code above updates the grid but the changes are not saved to the database.
dgvEmployeeInformation.EndEdit()
SQL.DBDS.Tables(0).AcceptChanges()
SQL.DBDA.Update(SQL.DBDS)
'txtADPID.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("ADPID").Value.ToString 'EmployeeInformation.ADPID
'cboVP.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("VP").Value.ToString 'EmployeeInformation.VP
End If
to first update your DB and than to update the datagrid from your DB.
Something like
Sql = "update TABLE_Name set FirstName = #fName" 'write all your query'
myCmd = New SqlCommand(Sql, myConn)
myCmd.Parameters.Add("#fName", SqlDbType.VarChar).Value = txtFirstName.Text
myCmd.ExecuteNonQuery()
MsgBox("Update complete.")
myConn.Close()
And than you can update your datagrid! I'm always used to connect my DataGrid to my SQL table, so the code will be:
Public Sub Updating()
Me.Table_NameTableAdapter.Fill(Me.DB_NameDataSet1.Table_Name)
End Sub
Got it to work:
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim dbconn As New SqlConnection("server=192.168.50.205;Database=SEMHC_Admin2018;trusted_Connection=True;")
Dim mycmd As SqlCommand
Dim mySQL As String
dbconn.Open()
If strEditType = "Add" Or strEditType = "Copy" Then
End If
If strEditType = "Edit" Then
mySQL = "update employeeInformation
set FirstName = #firstName,
LastName = #LastName,
SSN = #SSN,
EmployeeInformationID = #EmployeeInformationID,
Default_LocationID = #Default_LocationID,
EmployeeActive = #chkbxActive,
PrimaryFile = #chkbxPrimaryFile,
UnallocatedTime = #chkbxUnallocatedTime
from employeeInformation
WHERE SystemTableID = #SystemTableID
" 'write query'
mycmd = New SqlCommand(mySQL, dbconn)
mycmd.Parameters.Add("#SystemTableID", SqlDbType.VarChar).Value = txtTableID.Text
mycmd.Parameters.Add("#FirstName", SqlDbType.VarChar).Value = txtFirstName.Text
mycmd.Parameters.Add("#LastName", SqlDbType.VarChar).Value = txtLastName.Text
mycmd.Parameters.Add("#SSN", SqlDbType.VarChar).Value = txtSSN.Text
mycmd.Parameters.Add("#EmployeeInformationID", SqlDbType.VarChar).Value = txtEmployeeID.Text
mycmd.Parameters.Add("#Default_LocationID", SqlDbType.VarChar).Value = cboDefaultLocation.Text
mycmd.Parameters.Add("#chkbxActive", SqlDbType.VarChar).Value = chkbxActive.Checked
mycmd.Parameters.Add("#chkbxPrimaryFile", SqlDbType.VarChar).Value = chkbxPrimaryFile.Checked
mycmd.Parameters.Add("#chkbxUnallocatedTime", SqlDbType.VarChar).Value = chkbxUnallocatedTime.Checked
mycmd.ExecuteNonQuery()
'MsgBox("Update complete.")
dbconn.Close()
'SQL.DBDS.Tables(0).AcceptChanges()
'SQL.DBDA.Update(SQL.DBDS)
'txtADPID.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("ADPID").Value.ToString 'EmployeeInformation.ADPID
'cboVP.Text = dgvEmployeeInformation.Rows(dgvEmployeeInformation.CurrentRow.Index).Cells("VP").Value.ToString 'EmployeeInformation.VP
End If
ChangeFields()
ChangeButtons()
strEditType = ""
LoadGrid()
End Sub

WebBrowser and BackgroundWorker VB

Can a WebBrowser.DocumentCompleted event executes the BackgroundWorker.RunWorkerAsync() correctly? Because my program doesn't seem to execute the codes under BackgroundWorker.
Code:
Dim Status As String = ""
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If Status = "Enabled" Or Status = "Disabled" Then
Else
Status = WebBrowser1.Document.GetElementById(Account & "Flag").InnerText.ToString
If Status = "Enabled" Then
BackgroundWorker1.RunWorkerAsync()
ElseIf Status = "Disabled" Then
MessageBox.Show("disabled. Contact admin for more information.", "JKLorenzo", MessageBoxButtons.OK, MessageBoxIcon.Information)
Close()
End If
End If
End Sub
I finally made it to work
Here is the code i've used:
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
BackgroundWorker1.ReportProgress(10)
Dim mysqlconnection As MySqlConnection = New MySqlConnection("server=85.10.205.173;port=3306;username='" & User & "';password='" & Pass & "'")
BackgroundWorker1.ReportProgress(20)
Dim mysqlcommand As MySqlCommand = Nothing
BackgroundWorker1.ReportProgress(30)
Dim mysqldatareader As MySqlDataReader = Nothing
BackgroundWorker1.ReportProgress(40)
mysqlconnection.Open()
BackgroundWorker1.ReportProgress(50)
Using table As DataTable = New DataTable
BackgroundWorker1.ReportProgress(60)
Using command As MySqlCommand = New MySqlCommand("Select * from my.accounts where Username = 'Ray';", mysqlconnection)
BackgroundWorker1.ReportProgress(70)
Using adapter As MySqlDataAdapter = New MySqlDataAdapter(command)
BackgroundWorker1.ReportProgress(80)
adapter.Fill(table)
BackgroundWorker1.ReportProgress(90)
End Using
End Using
For Each row As DataRow In table.Rows
If row("Flag") = "enable" Then
e.Result = "1"
BackgroundWorker1.ReportProgress(100)
Else
e.Result = "0"
BackgroundWorker1.ReportProgress(100)
End If
Next
End Using
mysqlconnection.Close()
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
If e.ProgressPercentage = 10 Then
Label1.Text = "Status: Checking"
Label1.ForeColor = Color.FromKnownColor(KnownColor.Highlight)
End If
ProgressBar1.Value = e.ProgressPercentage
ProgressBar1.Refresh()
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
Threading.Thread.Sleep(500)
ProgressBar1.Value = 0
If e.Result = "1" Then
Label1.Text = "Status: Enabled"
Label1.ForeColor = Color.Green
Button1.Enabled = False
Button2.Enabled = True
ElseIf e.Result = "0" Then
Label1.Text = "Status: Disabled"
Label1.ForeColor = Color.OrangeRed
Button1.Enabled = True
Button2.Enabled = False
Else
MessageBox.Show("Unknown output: " & e.Result & " . Closing", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
Close()
End If
End Sub

Identifier expected? visual basic

im almost done with this and then that... hopefully someone will be able to help me (Really hope so atleast, cus i need to be done with this:P) (need more text cus there is to much code):
|error is there|>
Private Sub FlatButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FlatButton1_Click. <|error is there|
Dim Conn As New MySqlConnection("Not going to publish this")
If FlatTextBox1.Text = "" Then
MsgBox("No username specified")
FlatTextBox2.Text = ""
Else
If FlatTextBox2.Text = "" Then
MsgBox("No password specified")
FlatTextBox1.Text = ""
Else
Try
Me.Text = "Logging in..."
Conn.Open()
Dim sqlquery As String = "SELECT * FROM Testing WHERE Username = '" & FlatTextBox1.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
If data(2).ToString = FlatTextBox2.Text Then
Me.Text = "Logged in!"
My.Settings.Username = FlatTextBox1.Text
MsgBox("Welcome " + data(1).ToString)
Home.Show()
Me.Close()
If data(3).ToString = "1" Then
My.Settings.Admin = "Yes"
Else
My.Settings.Admin = "No"
End If
End If
Else
MsgBox("Failed Login")
End If
End While
Catch ex As Exception
End Try
End If
End If
End Sub
End Class
Replace these Lines
Private Sub FlatButton1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles FlatButton1_Click
With
Private Sub FlatButton1_Click(sender As Object, e As EventArgs) Handles FlatButton1_Click