To get started I created a program at work to read our network tools and store the retrieved data to our database. No problem but the way I set it up originally was every tool had its own instance and was hard coded for each tool.
Now I was tasked with making the program more user friendly so I can send it to other places. So now I database the IP address of tool and location on assembly line so I can cross reference while the code is executing.
On the new program I created an array of my Tool Reader class:
Dim TB(50) As ReadAtlascopco
Then I run through this loop on form load:
Private dict As New Dictionary(Of Timer, Label)()
Private Sub CreateTimers()
For i = 0 To IPCount
TB(i) = New ReadAtlascopco
' timer(i) = New Timerarray
Next
For i As Integer = 1 To IPCount
C = i - 1
timer = New Timer() With {.Interval = 250, .Enabled = True, .Tag = i.ToString}
AddHandler timer.Tick, (AddressOf timer_Tick)
' timer.Interval = (100 * i)
label = New Label()
label.Name = "label" & i
label.Location = New Point(10, 10 + i * 25)
label.Font = New Font("Sans Serif", 9, FontStyle.Bold)
label.AutoSize = True
'label.Width = 100
'label.AutoEllipsis = False
label.TabIndex = i
label.Visible = True
Me.Controls.Add(label)
dict(timer) = label
TB(C).ipaddress = TBData(C)
TB(C).StartConnection()
timer.Enabled = True
timer.Start()
Next
Then I go through the timer tick event. Everything works great up until this point. Once I go through the tick event it starts lagging and I miss data.
Is there a way to speed this process up?
Here is the tick event:
Private Sub timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
Dim Stop_Num(50) As String
Dim Line_Name(50) As String
Dim t As Timer = DirectCast(sender, Timer)
Dim s As Integer = Val(t.Tag) - 1
Param1 = TBData(s)
CWE(s) = False
If Activestat(s) = True Then
Dim SQL1 As String = "SELECT Stop_Num FROM TBL_Added_Boxes Where(IP_Address = N'" + Param1 + "')"
Dim output1 As String
Using cn = New SqlConnection(My.Settings.Torque_InfoConnectionString)
Using cmd = New SqlCommand(SQL1, cn)
cn.Open()
Try
Dim dr1 = cmd.ExecuteReader()
While dr1.Read()
output1 = dr1("Stop_Num").ToString()
End While
Catch ex As SqlException
WriteToErrorLog("Error pulling data from the database in reguards to torque box info (Stop Number).", ex.ToString(), "Failed to retreive Torque controler Info .")
End Try
cn.Close()
End Using
End Using
Stop_Num(0) = output1
Dim SQL2 As String = "SELECT Line_On FROM TBL_Added_Boxes Where(IP_Address = N'" + Param1 + "')"
Dim output2 As String
Using cn = New SqlConnection(My.Settings.Torque_InfoConnectionString)
Using cmd = New SqlCommand(SQL2, cn)
cn.Open()
Try
Dim dr2 = cmd.ExecuteReader()
While dr2.Read()
output2 = dr2("Line_On").ToString()
End While
Catch ex As SqlException
WriteToErrorLog("Error pulling data from the database in reguards to torque box info (Line On).", ex.ToString(), "Failed to retreive Torque controler Info .")
End Try
cn.Close()
End Using
End Using
Line_Name(0) = output2
If Line_Name(0) = "Line 1" Then
Newlinename(s) = "Line1Serial"
ElseIf Line_Name(0) = "Line 2" Then
Newlinename(s) = "Line2Serial"
ElseIf Line_Name(0) = "Line 3" Then
Newlinename(s) = "Line3Serial"
End If
Param3 = Stop_Num(0)
Param2 = Newlinename(s)
Dim SQL As String = "SELECT " + Newlinename(s) + " FROM TBL_RunningLineStatus Where(Stop_Number = N'" + Stop_Num(0) + "')"
Dim output As String
Using cn = New SqlConnection(My.Settings.ScanBypassConnectionString)
Using cmd = New SqlCommand(SQL, cn)
cn.Open()
Try
Dim dr = cmd.ExecuteReader()
While dr.Read()
output = dr(Param2).ToString()
End While
Catch ex As SqlException
WriteToErrorLog("Error Pulling Data From The Database In reguards to Seat Data.", ex.ToString(), "Failed to retreive buildline data.")
End Try
cn.Close()
End Using
End Using
TBSData(s) = output
If Killall = "True" Then
t.Stop()
Else
Try
TB(s).GetData()
If TB(s).Colorselect = 0 Then
dict(t).BackColor = System.Drawing.Color.GreenYellow
dict(t).ForeColor = Color.Black
ElseIf TB(s).Colorselect = 1 Then
TB(s).ipaddress = TBData(s)
TB(s).StartConnection()
dict(t).BackColor = System.Drawing.Color.Red
dict(t).ForeColor = Color.White
ElseIf TB(s).Colorselect = 2 Then
dict(t).BackColor = System.Drawing.Color.Purple
dict(t).ForeColor = Color.White
End If
If Olddata(s) <> TB(s).TorboxData(20) Then
Cname(s) = TB(s).TorboxData(2)
Tstatus(s) = TB(s).TorboxData(7)
TValue(s) = TB(s).TorboxData(19)
Sdata(s) = TBSData(s)
Tfinal(s) = TB(s).TorboxData(18)
TPset(s) = TB(s).TorboxData(30)
TFinalAngle(s) = TB(s).TorboxData(24)
RDAmin(s) = TB(s).TorboxData(25)
RDAmax(s) = TB(s).TorboxData(26)
RDAactual(s) = TB(s).TorboxData(27)
RDAStat(s) = TB(s).TorboxData(15)
Anglemin(s) = TB(s).TorboxData(21)
Anglemax(s) = TB(s).TorboxData(22)
AngleFT(s) = TB(s).TorboxData(23)
Anglestat(s) = TB(s).TorboxData(13)
Tormin(s) = TB(s).TorboxData(16)
Tormax(s) = TB(s).TorboxData(17)
TTTights(s) = TB(s).TorboxData(28)
TTSerial(s) = TB(s).TorboxData(29)
Olddata(s) = TB(s).TorboxData(20)
CWE(s) = True
dict(t).Text = t.Tag + " ) " + "Controler Name : " + TB(s).TorboxData(2) + ": Status : " + TB(s).Connectiontext + " : Date : " + Now() + " :: SERIAL # : " + Sdata(s) + " : From : " + Newlinename(s) + " :: Stop : " + Param3 + ""
' .Text = t.Tag + " ) " + "Controler Name : " + TB(s).TorboxData(2) + ": Status : " + TB(s).Connectiontext + " : Date : " + Now() + " :: SERIAL # : " + Sdata(s) + " : From : " + Newlinename(s) + " :: Stop : " + Param3 + "")
dict(t).BackColor = System.Drawing.Color.Yellow
Else
If TB(s).networkconnected = True Then
dict(t).AutoSize = True
'dict(t).Text = "Controler Name : " + TB(s).TorboxData(2) + ": Status : " + TB(s).Connectiontext + " : Date : " + Now()
dict(t).BackColor = System.Drawing.Color.Yellow
dict(t).ForeColor = Color.Black
Else
dict(t).Text = TB(s).Connectiontext + " :::: " + Now() + " :: " + TBData(s)
dict(t).BackColor = System.Drawing.Color.Red
dict(t).ForeColor = Color.White
End If
End If
Catch ex As Exception
WriteToErrorLog("Error Reading the torque box .", ex.Message, "Failed read torque data.")
Finally
'If CWE(s) = True Then
' Call Data_Entry()
'End If
If TValue(s) <> "" And CWE(s) = True Then
Try
con.ConnectionString = My.Settings.ScanBypassConnectionString
con.Open()
cmd.Connection = con
cmd.CommandText = "INSERT INTO TBL_Torque_Value1 (Serial_Num, Controler_Name, Torque_Status, Torque_Value, Date_Time,Extra_1, Extra_2, Extra_3,RundownMin,RundownMax,RundownAct,RundownStat,AngleMin,AngleMax,AngleFT,AngleStat,TorqueMin,TorqueMax,ToolTightens,Toolserialnum) VALUES(#p1,#p2, #p3, #p4, #p5, #p6, #p7, #p8,#p9, #p10, #p11, #p12, #p13, #p14, #p15, #p16, #p17, #p18, #p19, #p20)"
cmd.Parameters.Add("#p1", SqlDbType.NVarChar, 50)
cmd.Parameters.Add("#p2", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p3", SqlDbType.NVarChar, 50)
cmd.Parameters.Add("#p4", SqlDbType.NVarChar, 50)
cmd.Parameters.Add("#p5", SqlDbType.DateTime2, 7)
cmd.Parameters.Add("#p6", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p7", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p8", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p9", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p10", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p11", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p12", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p13", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p14", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p15", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p16", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p17", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p18", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p19", SqlDbType.NVarChar, 250)
cmd.Parameters.Add("#p20", SqlDbType.NVarChar, 250)
cmd.Parameters("#p1").Value = Sdata(s)
cmd.Parameters("#p2").Value = Cname(s)
cmd.Parameters("#p3").Value = Tstatus(s)
cmd.Parameters("#p4").Value = TValue(s)
cmd.Parameters("#p5").Value = Now()
cmd.Parameters("#p6").Value = Tfinal(s)
cmd.Parameters("#p7").Value = TFinalAngle(s) + " Deg"
cmd.Parameters("#p8").Value = "P:" + TPset(s)
cmd.Parameters("#p9").Value = RDAmin(s)
cmd.Parameters("#p10").Value = RDAmax(s)
cmd.Parameters("#p11").Value = RDAactual(s)
cmd.Parameters("#p12").Value = RDAStat(s)
cmd.Parameters("#p13").Value = Anglemin(s)
cmd.Parameters("#p14").Value = Anglemax(s)
cmd.Parameters("#p15").Value = AngleFT(s)
cmd.Parameters("#p16").Value = Anglestat(s)
cmd.Parameters("#p17").Value = Tormin(s)
cmd.Parameters("#p18").Value = Tormax(s)
cmd.Parameters("#p19").Value = TTTights(s)
cmd.Parameters("#p20").Value = TTSerial(s)
cmd.ExecuteNonQuery()
Catch ex As Exception
WriteToErrorLog("Error Inserting Data into The Database In reguards to Torque Data.", ex.Message, "Failed to Insert Torque Data.")
con.Close()
cmd.Parameters.Clear()
Cname(s) = ""
Tstatus(s) = ""
TValue(s) = ""
Sdata(s) = ""
Tfinal(s) = ""
TFinalAngle(s) = ""
TPset(s) = ""
RDAmin(s) = ""
RDAmax(s) = ""
RDAactual(s) = ""
RDAStat(s) = ""
Anglemin(s) = ""
Anglemax(s) = ""
AngleFT(s) = ""
Anglestat(s) = ""
Tormin(s) = ""
Tormax(s) = ""
TTTights(s) = ""
TTSerial(s) = ""
Finally
con.Close()
cmd.Parameters.Clear()
Cname(s) = ""
Tstatus(s) = ""
TValue(s) = ""
Sdata(s) = ""
Tfinal(s) = ""
TFinalAngle(s) = ""
TPset(s) = ""
RDAmin(s) = ""
RDAmax(s) = ""
RDAactual(s) = ""
RDAStat(s) = ""
Anglemin(s) = ""
Anglemax(s) = ""
AngleFT(s) = ""
Anglestat(s) = ""
Tormin(s) = ""
Tormax(s) = ""
TTTights(s) = ""
TTSerial(s) = ""
End Try
End If
End Try
End If
Else
dict(t).AutoSize = True
dict(t).Text = "Torque Box is not active :: " + TBData(s) + " ::"
dict(t).BackColor = System.Drawing.Color.Black
dict(t).ForeColor = Color.White
End If
End Sub
The class that is being referenced is one that I created and is working but like I said everything is slow. It seems to hang for 3 to 5 seconds in a single tick event.
As of now I only have 21 tools setup and it will take about 15 to 30 seconds to cycle through all.
I have 5 tab pages, with a Datagridview in each pages. Each tab represents a table in my database. The problem is, when updating, only the first table is being updated. Here's my code:
Private Sub update_Click(sender As Object, e As EventArgs) Handles updateBtn.Click
'/// UPDATING TABLE - employee
Try
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Employee.mdb;")
conn.Open()
Dim command As New OleDbCommand("UPDATE employee SET [Last_Name] = #lname, [First_Name]= #fname, MI = #mi, Bday = #bday, Age = #age, [Nationality] = #natio, [Contact_Number] = #contact, Sex = #gender, Address = #address, Department = #department, [Position] = #position, TIN = #tin, SSS = #sss, Pagibig = #pagibig, PhilHealth = #phh, Termi_Resi = #termiresi, [Date_hired] = #datehired, [Rate_Month] = #rm, [Date_End] = #dateTermiResi, Status = #status, [Father_Name] = #father, [Mother_Name] = #mother, Civil = #civil, Spouse = #spouse, [Number_of_Children] = #numberchild, Child1 = #child1, Child2 = #child2, Child3 = #child3, Child4 = #child4, Child5 = #child5, Child6 = #child6, Child7 = #child7, Child8 = #child8, Child9 = #child9 WHERE [EmployID] = #numberemp", conn)
With command.Parameters
.AddWithValue("#lname", lname.Text)
.AddWithValue("#fname", fname.Text)
.AddWithValue("#mi", mi.Text)
.AddWithValue("#bday", bday.Value)
.AddWithValue("#age", age.Text)
.AddWithValue("#natio", natio.Text)
.AddWithValue("#contact", contact.Text)
.AddWithValue("#gender", gender.Text)
.AddWithValue("#address", address.Text)
.AddWithValue("#department", department.Text)
.AddWithValue("#position", position.Text)
.AddWithValue("#tim", tin.Text)
.AddWithValue("#sss", sss.Text)
.AddWithValue("#pagibig", pagibig.Text)
.AddWithValue("#phh", phh.Text)
.AddWithValue("#termiresi", termiresi.Text)
.AddWithValue("#datehired", datehired.Value)
.AddWithValue("#rm", rm.Text)
.AddWithValue("#dateTermiResi", dateTermiResi.Value)
.AddWithValue("#status", status.Text)
.AddWithValue("#father", father.Text)
.AddWithValue("#mother", mother.Text)
.AddWithValue("#civil", civil.Text)
.AddWithValue("#spouse", spouse.Text)
.AddWithValue("#numberchild", numberchild.Text)
.AddWithValue("#child1", child1.Text)
.AddWithValue("#child2", child2.Text)
.AddWithValue("#child3", child3.Text)
.AddWithValue("#child4", child4.Text)
.AddWithValue("#child5", child5.Text)
.AddWithValue("#child6", child6.Text)
.AddWithValue("#child7", child7.Text)
.AddWithValue("#child8", child8.Text)
.AddWithValue("#child9", child9.Text)
.AddWithValue("#numberemp", numberemp.Text)
End With
command.ExecuteNonQuery()
MessageBox.Show("Employee's Informations Successfuly Updated!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
command.Dispose()
conn.Close()
clearall()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
'/// UPDATING TABLE - education
Try
Using conn2 As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Employee.mdb;")
conn2.Open()
Dim command2 As New OleDbCommand("UPDATE education SET Level_Educ = #hlevelEduc, Degree = #degree, Post_Degree = #postdegree, Elem = #elem, Year_one = #year1, Highschool = #highschool, Year_two = #year2, College = #college, Year_three = #year3, Training_School = #trainingS, Year_four = #year4, Other_Educ = #otherEduc WHERE [EmployID] = #numberemp1", conn2)
numberemp1.Text = numberemp.Text
With command2.Parameters
.AddWithValue("#hlevelEduc", hlevelEduc.Text)
.AddWithValue("#elem", elem.Text)
.AddWithValue("#year1", year1.Text)
.AddWithValue("#highschool", highschool.Text)
.AddWithValue("#year2", year2.Text)
.AddWithValue("#college", college.Text)
.AddWithValue("#year3", year3.Text)
.AddWithValue("#degree", degree.Text)
.AddWithValue("#postdegree", postdegree.Text)
.AddWithValue("#trainingS", trainingS.Text)
.AddWithValue("#year4", year4.Text)
.AddWithValue("#otherEduc", otherEduc.Text)
.AddWithValue("#numberemp1", numberemp1.Text)
End With
Dim rows = command2.ExecuteNonQuery()
If rows = 0 Then
MessageBox.Show("No rows modified")
Else
MessageBox.Show("Employee's Informations Successfuly Updated!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
command2.Dispose()
conn2.Close()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
'/// UPDATING TABLE - employment
Try
Using conn3 As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Employee.mdb;")
conn3.Open()
Dim command3 As New OleDbCommand("UPDATE employment SET Cname1 = #cname1, Posi1 = #posi1, Dept1 = #dept1, Tm1 = #tm1, Reason1 = #reason1, Cname2 = #cname2, Posi2 = #posi2, Dept2 = #dept2, Tm2 = #tm2, Reason2 = #reason2, Cname3 = #cname3, Posi3 = #posi3, Dept3 = #dept3, Tm3 = #tm3, Reason3 = #reason3, Cname4 = #cname4, Posi4 = #posi4, Dept4 = #dept4, Tm4 = #tm4, Reason4 = #reason4, Cname5 = #cname5, Posi5 = #posi5, Dept5 = #dept5, Tm5 = #tm5, Reason5 = #reason5, Cname6 = #cname6, Posi6 = #posi6, Dept6 = #dept6, Tm6 = #tm6, Reason6 = #reason6 WHERE [EmployID] = #numberemp2", conn3)
numberemp2.Text = numberemp.Text
With command3.Parameters
.AddWithValue("#cname1", cname1.Text)
.AddWithValue("#posi1", posi1.Text)
.AddWithValue("#dept1", dept1.Text)
.AddWithValue("#tm1", tm1.Text)
.AddWithValue("#reason1", reason1.Text)
.AddWithValue("#cname2", cname2.Text)
.AddWithValue("#posi2", posi2.Text)
.AddWithValue("#dept2", dept2.Text)
.AddWithValue("#tm2", tm2.Text)
.AddWithValue("#reason2", reason2.Text)
.AddWithValue("#cname3", cname3.Text)
.AddWithValue("#posi3", posi3.Text)
.AddWithValue("#dept3", dept3.Text)
.AddWithValue("#tm3", tm3.Text)
.AddWithValue("#reason3", reason3.Text)
.AddWithValue("#cname4", cname4.Text)
.AddWithValue("#posi4", posi4.Text)
.AddWithValue("#dept4", dept4.Text)
.AddWithValue("#tm4", tm4.Text)
.AddWithValue("#reason4", reason4.Text)
.AddWithValue("#cname5", cname5.Text)
.AddWithValue("#posi5", posi5.Text)
.AddWithValue("#dept5", dept5.Text)
.AddWithValue("#tm5", tm5.Text)
.AddWithValue("#reason5", reason5.Text)
.AddWithValue("#cname6", cname6.Text)
.AddWithValue("#posi6", posi6.Text)
.AddWithValue("#dept6", dept6.Text)
.AddWithValue("#tm6", tm6.Text)
.AddWithValue("#reason6", reason6.Text)
.AddWithValue("#numberemp2", numberemp2.Text)
End With
Dim rows = command3.ExecuteNonQuery()
If rows = 0 Then
MessageBox.Show("No rows modified")
Else
MessageBox.Show("Employee's Informations Successfuly Updated!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
command3.Dispose()
conn3.Close()
clearall()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
'/// UPDATING TABLE - disciplinary
Try
Using conn4 As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Employee.mdb;")
conn4.Open()
Dim command4 As New OleDbCommand("UPDATE disciplinary SET Offense1 = #o1, Action1 = #ao1, Dateoff1 = #do1, Offense2 = #o2, Action2 = #ao2, Dateoff2 = #do2, Offense3 = #o3, Action3 = #ao3, Dateoff3 = #do3, Offense4 = #o4, Action4 = #ao4, Dateoff4 = #do4, Offense5 = #o5, Action5 = #ao5, Dateoff5 = #do5, Offense6 = #o6, Action6 = #ao6, Dateoff6 = #do6, Offense7 = #o7, Action7 = #ao7, Dateoff7 = #do7, Offense8 = #o8, Action8 = #ao8, Dateoff8 = #do8, Offense9 = #o9, Action9 = #ao9, Dateoff9 = #do9, Offense10 = #10, Action10 = #ao10, Dateoff10 = #do10 WHERE [EmployID] = #numberemp3 ", conn4)
numberemp3.Text = numberemp.Text
With command4.Parameters
.AddWithValue("#o1", o1.Text)
.AddWithValue("#ao1", ao1.Text)
.AddWithValue("#do1", do1.Value)
.AddWithValue("#o2", o2.Text)
.AddWithValue("#ao2", ao2.Text)
.AddWithValue("#do2", do2.Value)
.AddWithValue("#o3", o3.Text)
.AddWithValue("ao3", ao3.Text)
.AddWithValue("#do3", do3.Value)
.AddWithValue("#o4", o4.Text)
.AddWithValue("#ao4", ao4.Text)
.AddWithValue("#do4", do4.Value)
.AddWithValue("#o5", o5.Text)
.AddWithValue("#ao5", ao5.Text)
.AddWithValue("#do5", do5.Value)
.AddWithValue("#o6", o6.Text)
.AddWithValue("#ao6", ao6.Text)
.AddWithValue("#do6", do6.Value)
.AddWithValue("#o7", o7.Text)
.AddWithValue("#ao7", ao7.Text)
.AddWithValue("#do7", do7.Value)
.AddWithValue("#o8", o8.Text)
.AddWithValue("#ao8", ao8.Text)
.AddWithValue("#do8", do8.Value)
.AddWithValue("#o9", o9.Text)
.AddWithValue("#ao9", ao9.Text)
.AddWithValue("#do9", do9.Value)
.AddWithValue("#o10", o10.Text)
.AddWithValue("#ao10", ao10.Text)
.AddWithValue("#do10", do10.Value)
.AddWithValue("#numberemp3", numberemp3.Text)
End With
Dim rows = command4.ExecuteNonQuery()
If rows = 0 Then
MessageBox.Show("No rows modified")
Else
MessageBox.Show("Employee's Informations Successfuly Updated!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
conn4.Close()
clearall()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
'/// UPDATING TABLE - trainings
Try
Using conn5 As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Employee.mdb;")
conn5.Open()
Dim command5 As New OleDbCommand("UPDATE trainings SET ts1 = #ts1, dts1 = #dts1, ts2 = #ts2, dts2 = #dts2, ts3 = #ts3, dts3 = #dts3, ts4 = #ts4, dts4 = #dts4, ts5 = #ts5, dts5 = #dts5, ts6 = #ts6, dts6 = #dts6, ts7 = #ts7, dts7 = #dts7, ts8 = #ts8, dts8 = #dts8, ts9 = #ts9, dts9 = #dts9, ts10 = #ts10, dts10 = #dts10, ts11 = #ts11, dts11 = #dts11, ts12 = #ts12, dts12 = #dts12, ts13 = #ts13, dts13 = #dts13, ts14 = #ts14, dts14 = #dts14, ts15 = #ts15, dts15 = #dts15, ts16 = #ts16, dts16 = #dts16, ts17 = #ts17, dts17 = #dts17, ts18 = #ts18, dts18 = #dts18, ts19 = #ts19, dts19 = #dts19, ts20 = #ts20, dts20 = #dts20, ts21 = #ts21, dts21 = #dts21, ts22 = #ts22, dts22 = #dts22, ts23 = #ts23, dts23 = #dts23, ts24 = #ts24, dts24 = #dts24 WHERE [EmployID] = #numberemp4 ", conn5)
numberemp4.Text = numberemp.Text
With command5.Parameters
.AddWithValue("#ts1", ts1.Text)
.AddWithValue("#dts1", dts1.Value)
.AddWithValue("#ts2", ts2.Text)
.AddWithValue("#dts2", dts2.Value)
.AddWithValue("#ts3", ts3.Text)
.AddWithValue("#dts3", dts3.Value)
.AddWithValue("#ts4", ts4.Text)
.AddWithValue("#dts4", dts4.Value)
.AddWithValue("#ts5", ts5.Text)
.AddWithValue("#dts5", dts5.Value)
.AddWithValue("#ts6", ts6.Text)
.AddWithValue("#dts6", dts6.Value)
.AddWithValue("#ts7", ts7.Text)
.AddWithValue("#dts7", dts7.Value)
.AddWithValue("#ts8", ts8.Text)
.AddWithValue("#dts8", dts8.Value)
.AddWithValue("#ts9", ts9.Text)
.AddWithValue("#dts9", dts9.Value)
.AddWithValue("#ts10", ts10.Text)
.AddWithValue("#dts10", dts10.Value)
.AddWithValue("#ts11", ts11.Text)
.AddWithValue("#dts11", dts11.Value)
.AddWithValue("#ts12", ts12.Text)
.AddWithValue("#dts12", dts12.Value)
.AddWithValue("#ts13", ts13.Text)
.AddWithValue("#dts13", dts13.Value)
.AddWithValue("#ts14", ts14.Text)
.AddWithValue("#dts14", dts14.Value)
.AddWithValue("#ts15", ts15.Text)
.AddWithValue("#dts15", dts15.Value)
.AddWithValue("#ts16", ts16.Text)
.AddWithValue("#dts16", dts16.Value)
.AddWithValue("#ts17", ts17.Text)
.AddWithValue("#dts17", dts17.Value)
.AddWithValue("#ts18", ts18.Text)
.AddWithValue("#dts18", dts18.Value)
.AddWithValue("#ts19", ts19.Text)
.AddWithValue("#dts19", dts19.Value)
.AddWithValue("#ts20", ts20.Text)
.AddWithValue("#dts20", dts20.Value)
.AddWithValue("#ts21", ts21.Text)
.AddWithValue("#dts21", dts21.Value)
.AddWithValue("#ts22", ts22.Text)
.AddWithValue("#dts22", dts22.Value)
.AddWithValue("#ts23", ts23.Text)
.AddWithValue("#dts23", dts23.Value)
.AddWithValue("#ts24", ts24.Text)
.AddWithValue("#dts24", dts24.Value)
.AddWithValue("#numberemp4", numberemp4.Text)
End With
Dim rows = command5.ExecuteNonQuery()
If rows = 0 Then
MessageBox.Show("No rows modified")
Else
MessageBox.Show("Employee's Informations Successfuly Updated!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
command5.Dispose()
conn5.Close()
disableall()
clearall()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Add1.Visible = True
btnReg.Visible = True
updateBtn.Visible = False
RefreshDGV()
End Sub
I always get
No rows modified
when updating the second up to the fifth table.
Here's my form to make it clear if it is too confusing..
Assuming that you want to load data to tab pages when needed:
Use the Load event to load data for Tap Page 1
hook up to event Selecting of TabControl to load data for the other pages
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e) {
if (e.TabPage.Name == "TabPage1") {
//Load Data for Tab page 1
DataTable dt = new DataTable();
dt.Load(reader);
grid2.DataSource = dt;
}
}
My chart loads data from a DataGridView.
I want to automatically update my chart with new data if new values are inserted into the DataGridView.
My chart is bound to table1 and table2 in my DataGridView which gets values from a DataTable. Here is a small portion of the code:
Dim myData As New DataTable
wcAdapter.SelectCommand = wcCommand
wcAdapter.Fill(myData)
-
Chart1.DataSource = myData
Chart1.Series("Series1").ValueMemberX = "table1"
Chart1.Series("Series1").ValueMembersY = "table2"
Here is the complete code:
Try
wcconn.Open()
Dim wcCommand As New MySqlCommand()
''telesales name
' Dim wcQuery = "SELECT ID, Telesales, SUBSTRING(lastupdatedate, 1, 10) as 'Day', SUBSTRING(lastupdatetime FROM -9 FOR 6) as 'Time' FROM ratingout where Telesales='" & cbTelesales.Text & "' and lastupdatedate= '" & newDate & "' and lastupdatedate is not null and lastupdatetime is not null ORDER BY lastupdatetime ;"
' wcCommand.Connection = wcconn
' wcCommand.CommandText = wcQuery
Dim newDate As String
newDate = dateWorkCheck.Text
newDate = newDate.Replace("/", "-")
Dim y, m, d As String
y = newDate.Substring(6, 4)
m = newDate.Substring(3, 2)
d = newDate.Substring(0, 2)
newDate = y & "-" & m & "-" & d
Dim wcQuery = "SELECT ID, Telesales, lastupdatedate as 'Day', SUBSTRING(lastupdatetime FROM -8 FOR 2) as 'Time' FROM ratingout where Telesales='" & cbTelesales.Text & "' and lastupdatedate= '" & newDate & "' and lastupdatedate is not null and lastupdatetime is not null ORDER BY lastupdatetime ;"
wcCommand.Connection = wcconn
wcCommand.CommandText = wcQuery
Dim wcData As New DataTable
wcAdapter.SelectCommand = wcCommand
wcAdapter.Fill(wcData)
Dim i = 0
If wcData.Rows.Count = 0 Then
wcAdapter.Dispose()
Try
Dim wQuery = "SELECT ID, Telesales, lastupdatedate as 'Day', SUBSTRING(lastupdatetime FROM -8 FOR 2) as 'Time' FROM ratingout where Telesales='" & cbTelesales.Text & "' and lastupdatedate= '" & dateWorkCheck.Text & "' and lastupdatedate is not null and lastupdatetime is not null ORDER BY lastupdatetime ;"
wcCommand.Connection = wcconn
wcCommand.CommandText = wQuery
Dim wData As New DataTable
wcAdapter.SelectCommand = wcCommand
wcAdapter.Fill(wData)
wData.Columns.Add("tt")
wData.Columns.Add("num")
wcData.Columns.Add("tt")
wcData.Columns.Add("num")
'dgvWorkCheck.AutoSizeRowsMode = DataGridViewAutoSizeRowMode.AllCells
Dim dr As DataRow
For Each dr In wData.Rows
If lastV Is Nothing OrElse Not ColumnEqual(lastV, dr("Time")) Then
''check if first value is nothing
If lastV = Nothing Then
lastV = "00"
l = "0"
Else
dr("tt") = lastV
dr("num") = l
'wcData.Tables("ratingout").Rows(I)("ID") = dr("ID")
End If
ListBox1.Items.Add(lastV & " <--> " & l)
lastV = dr("Time")
l = 1
ElseIf lastV Is Nothing OrElse ColumnEqual(lastV, dr("Time")) Then
l += 1
'Dim series1 As New Series()
'series1.Points.Add(l)
End If
For I = I To wData.Rows.Count
If I <> wData.Rows.Count Then
I += 1
If i = wData.Rows.Count Then
dr("tt") = lastV
dr("num") = l
ListBox1.BeginUpdate()
ListBox1.Items.Add(dr("Telesales") & " between[" & lastV & " and 17:00, ] <--> " & l & "[ records ]")
ListBox1.EndUpdate()
End If
GoTo n
Else
MsgBox("last data")
End If
Next
n:
Next
txtRec.Text = wData.Rows.Count
dgvWorkCheck.DataSource = wData
''chart
Dim ChartArea2 As ChartArea = New ChartArea()
Dim Legend2 As Legend = New Legend()
Dim Series2 As Series = New Series()
Dim Chart2 = New Chart()
Me.Controls.Add(Chart2)
ChartArea2.AxisX.LabelStyle.Angle = -90
ChartArea2.AxisX.LabelStyle.Interval = 1
ChartArea2.AxisY.LabelStyle.Angle = -90
ChartArea2.AxisY.LabelStyle.Interval = 5
ChartArea2.Name = "ChartArea2"
Chart2.ChartAreas.Add(ChartArea2)
Legend2.Name = "Legend2"
Chart2.Legends.Add(Legend2)
Chart2.Location = New System.Drawing.Point(12, 113)
Chart2.Name = "Chart2"
Series2.ChartArea = "ChartArea2"
Series2.Legend = "Legend2"
Series2.Name = "Series2"
Chart2.Series.Add(Series2)
Chart2.Size = New System.Drawing.Size(1145, 604)
Chart2.TabIndex = 0
Chart2.Text = "Chart2"
Chart2.Series("Series2").XValueMember = "tt"
Chart2.Series("Series2").YValueMembers = "num"
Chart2.DataSource = dgvWorkCheck.DataSource
Chart2.DataBind()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Exit Try
since the new data is inserted into a database, you will only need to rebind the gridview to it's source in order to display the new incoming data.
You should isolate the code that binds data to your chart in a function and have it called every time a new field gets inserted:
Function FillChartWithData()
Dim myData As New DataTable
wcAdapter.SelectCommand = wcCommand
wcAdapter.Fill(myData)
...
Chart1.Series("Series1").ValueMemberX = "table1"
Chart1.Series("Series1").ValueMembersY = "table2"
End Function
EDIT
I looked at your coded and it seems you're missing the part responsible for inserting new data inside the 'ratingout' table. You should create a function that allows you to insert new data, something along the line of:
Dim insertRating = "INSERT INTO ratingout VALUES (#NewTeleSalesName, #NewDate);"
Dim insertCmd As New MySqlCommand(insertRating, wcconn)
insertCmd.Parameters.Add("#NewTeleSalesName", MySqlDbType.VarChar, 255, "teleSalesName")
insertCmd.Parameters.Add("#NewDate", MySqlDbType.Datetime, 8, New DateTime(2010, 8, 5))
insertCmd.ExecuteNonQuery()
In order to update my chart bargraph named CashChart (which was databound to a BindingSource) I had to do the following:
To clear the chart information,
Clear the bounding source information
And then re-assign the bounding source information: for example:
CashChart.Series(0).Points.Clear()
CashChart.DataSource = ""
CashChart.DataSource = ESTADOINSTANTANEOBindingSource
Before, only my DataTable was updating, but after these commands, I was able to get the bargraph to update with new values in the table.