Click here to Skip to main content
15,943,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
pls some one help me... i use 3 tables with different column..and it all listed inside the save button...

it just executed but nothing is change when i click save to save the changes i made plsss help me some one ..base on my code do i missing codes to fix it?
i am using MYSQL database and VB

What I have tried:

Private Sub PictureBox2_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox2.Click
     Try
         If Label25.Text = "UPDATE" Then
             PictureBox7.Enabled = False
             Label24.Enabled = False
             enabledID()
             cboSSS.Checked = True
             cboBIR.Checked = True
             cboPag.Checked = True
             cbophil.Checked = True
             Label25.Text = "SAVE"

         ElseIf Label25.Text = "SAVE" Then
             conn.Open()
             query = New MySqlCommand("UPDATE info_info SET employee_count1=@employee_count1,employee_ID=@employee_ID,month=@month,days=@days,year=@year,Name=@Name,position=@position,regular=@regular,totalday=@totalday,month1=@month1,day1=@day1,month2=@month2,day2=@day2,percent=@percent,amount=@amount,percent1=@percent1,amount1=@amount1,percent2=@percent2,amount2=@amount2,percent3=@percent3,amount3=@amount3,overtime=@overtime,holiday=@holiday,special=@special,total=@total,deduction=@deduction+1,date1=@date1,cash_advance=@cash_advance,net=@net,late=@late,under_time=@under_time,absent=@absent where employee_count1=@employee_count1", conn)
             query.Parameters.AddWithValue("@employee_count1", gen)
             query.Parameters.AddWithValue("@employee_ID", txtID.Text)
             query.Parameters.AddWithValue("@month", txtmonth.Text)
             query.Parameters.AddWithValue("@days", txtdays.Text)
             query.Parameters.AddWithValue("@year", txtyear.Text)
             query.Parameters.AddWithValue("@Name", txtlastname.Text)
             query.Parameters.AddWithValue("@position", txtposition.Text)
             query.Parameters.AddWithValue("@regular", txtregular.Text)
             query.Parameters.AddWithValue("@totalday", txtotot.Text)
             query.Parameters.AddWithValue("@month1", txtfrom.Text)
             query.Parameters.AddWithValue("@day1", txtfrom1.Text)
             query.Parameters.AddWithValue("@month2", txtto.Text)
             query.Parameters.AddWithValue("@day2", txtto1.Text)
             query.Parameters.AddWithValue("@percent", txtcent.Text)
             query.Parameters.AddWithValue("@amount", txttot.Text)
             query.Parameters.AddWithValue("@percent1", txtcent1.Text)
             query.Parameters.AddWithValue("@amount1", txttot1.Text)
             query.Parameters.AddWithValue("@percent2", txtcent2.Text)
             query.Parameters.AddWithValue("@amount2", txttot2.Text)
             query.Parameters.AddWithValue("@percent3", txtcent3.Text)
             query.Parameters.AddWithValue("@amount3", txttot33.Text)
             query.Parameters.AddWithValue("@overtime", txtovt.Text)
             query.Parameters.AddWithValue("@holiday", txtper.Text)
             query.Parameters.AddWithValue("@special", txtsped.Text)
             query.Parameters.AddWithValue("@total", txtnon.Text)
             query.Parameters.AddWithValue("@deduction", txtamount.Text)
             query.Parameters.AddWithValue("@date1", txtday2.Text)
             query.Parameters.AddWithValue("@cash_advance", txtcash.Text)
             query.Parameters.AddWithValue("@net", txtnet.Text)
             query.Parameters.AddWithValue("@late", txtabsent.Text)
             query.Parameters.AddWithValue("@under_time", txtunder.Text)
             query.Parameters.AddWithValue("@absent", txtlate.Text)
             query.ExecuteNonQuery()
             conn.Close()


             conn.Open()
             query2 = New MySqlCommand("UPDATE deduction_table SET employee_count3=@employee_count3,employee_ID=@employee_ID,month=@month,days=@days,year=@year,Name=@Name,SSS=@SSS,BIR=@BIR,Pag_ibig=@Pag_ibig,Philhealth=@Philhealth where employee_count3=@employee_count3", conn)
             query2.Parameters.AddWithValue("@employee_count3", gen)
             query2.Parameters.AddWithValue("@employee_ID", txtID.Text)
             query2.Parameters.AddWithValue("@month", txtmonth.Text)
             query2.Parameters.AddWithValue("@days", txtdays.Text)
             query2.Parameters.AddWithValue("@year", txtyear.Text)
             query2.Parameters.AddWithValue("@Name", txtlastname.Text)
             query2.Parameters.AddWithValue("@SSS", txttot.Text)
             query2.Parameters.AddWithValue("@BIR", txttot1.Text)
             query2.Parameters.AddWithValue("@Pag_ibig", txttot2.Text)
             query2.Parameters.AddWithValue("@Philhealth", txttot33.Text)
             query2.ExecuteNonQuery()

             conn.Close()

             conn.Open()
             query3 = New MySqlCommand("UPDATE netpay_table SET employee_count4=@employee_count4,employee_ID=@employee_ID,month=@month,days=@days,year=@year,Name=@Name,net=@net  where employee_count4=@employee_count4", conn)
             query3.Parameters.AddWithValue("@employee_count4", gen)
             query3.Parameters.AddWithValue("@employee_ID", txtID.Text)
             query3.Parameters.AddWithValue("@month", txtmonth.Text)
             query3.Parameters.AddWithValue("@days", txtdays.Text)
             query3.Parameters.AddWithValue("@year", txtyear.Text)
             query3.Parameters.AddWithValue("@Name", txtlastname.Text)
             query3.Parameters.AddWithValue("@net", txtnet.Text)
             query3.ExecuteNonQuery()

             conn.Close()
             disabledID()
             Label25.Text = "UPDATE"
             MsgBox("successfully save")
             generalID()
             Label24.Enabled = True
             PictureBox7.Enabled = True

         End If
     Catch ex As Exception
         MsgBox(ex.ToString)
     Finally
         conn.Close()

     End Try
 End Sub
Posted
Updated 3-Apr-18 3:14am
Comments
CaThey Joy Galias 3-Apr-18 4:46am    
Pls some one share their idea
Christiaan van Bergen 3-Apr-18 5:15am    
So no exceptions are thrown? Okay, you are working with update statements, if no records are updated, then there was nothing to update. Use the result from the query.ExecuteNonQuery() to determine how many rows were updated.
CaThey Joy Galias 3-Apr-18 5:27am    
How? Sorry i dont know how can u give an example code
Christiaan van Bergen 3-Apr-18 5:43am    
Blunt way would be to show the affected rows in a MessageBox. Change all your ExecuteNonQuery() statements into something like: MsgBox("query1 rows: " + query1.ExecuteNonQuery())
Or put the result of the ExecuteNonQuery() in a variable and watch it while debugging.
CaThey Joy Galias 3-Apr-18 5:51am    
Ty tian i already solve it thank you very much for your idea.

So no exceptions are thrown? Okay, you are working with update statements, if no records are updated, then there was nothing to update. Use the result from the ExecuteNonQuery
VB
query.ExecuteNonQuery()
to determine how many rows were updated.
Blunt way would be to show the affected rows in a MessageBox. Change all your ExecuteNonQuery() statements into something like:
VB
MsgBox("query1 rows: " + query1.ExecuteNonQuery())
Or better yet, put the result of the ExecuteNonQuery() in a variable and watch it while debugging.
 
Share this answer
 
Use Sql Stored procedures to do more than you expected.

com.Parameters.Clear()
com.CommandText = "USP_PROCEDURE_NAME"
com.Parameters.Add("@parametertoppass", Datatype).Value = Valuetosent
'list of parameter you want to sent to procedure
com.CommandType = CommandType.StoredProcedure
com.Connection = cn
com.executenonquery()


through above you can send data one time to database and you can save or update to multiple table

here is the tutorial for stored procedure[^]
syntax to create stored procedure[^]

Advantage of stored procedure you can reduce more time taken to connect with your database
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900