Click here to Skip to main content
15,893,663 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questionprinter status Pin
wkalo8-Sep-12 1:22
wkalo8-Sep-12 1:22 
AnswerRe: printer status Pin
Eddy Vluggen8-Sep-12 4:52
professionalEddy Vluggen8-Sep-12 4:52 
GeneralRe: printer status Pin
wkalo8-Sep-12 20:45
wkalo8-Sep-12 20:45 
GeneralRe: printer status Pin
wkalo8-Sep-12 22:22
wkalo8-Sep-12 22:22 
GeneralRe: printer status Pin
Eddy Vluggen9-Sep-12 6:29
professionalEddy Vluggen9-Sep-12 6:29 
QuestionUpdate previous date data and then update the rest of the data Pin
garyu877-Sep-12 22:22
garyu877-Sep-12 22:22 
AnswerRe: Update previous date data and then update the rest of the data Pin
David Mujica10-Sep-12 3:52
David Mujica10-Sep-12 3:52 
GeneralRe: Update previous date data and then update the rest of the data Pin
garyu8711-Sep-12 3:19
garyu8711-Sep-12 3:19 
Firstly, thank you very much for the kind info but I am not sure of that.

My program is an Expenses Management. The User's will enter values to the prepared templates and then save.
When the user wanted to add a new data for the next date. Here the previous data wallet will be at the new data input template where the user will start entering value and then the wallet value will decrease and saved.(Add data is perfectly fine)

The problem is in editing(Update data). When I edit the 1st data its normal for the wallet's value to changed right and then save. Here's the problem, the changed wallet value have to be pass to the next data wallet and minus the other value to get the true value; as well as, the rest of the data.

So, how do I update these data because update only updates a selected row data only or to say how to get the wallet amount correct onwards from the other rows from the middle or previous row?

I have multiple tables that is an one to one relationship to a main table where the inside the main table has Wallet in it.
I'll show my working update statement and auto calculation here for better understanding:

Quote:
Sub Update_Data()
Try
UpdateFnB = "Update tblFoodAndBeverage SET Breakfast = @Breakfast, Lunch = @Lunch, Dinner = @Dinner, Supper = @Supper, Snack = @Snack, Beverage = @Beverage, Grocerries = @Grocerries, Sub_Total = @SubFnB WHERE Food_And_BeverageID = '" & LVDailyExpenses.DataGridView1.CurrentRow.Cells(0).Value.ToString & "' "
sqlFnB = New SqlCommand(UpdateFnB, connection)
sqlFnB.Parameters.AddWithValue("@Breakfast", txtBreakFeast.Text)
sqlFnB.Parameters.AddWithValue("@Lunch", txtLunch.Text)
sqlFnB.Parameters.AddWithValue("@Dinner", txtDinner.Text)
sqlFnB.Parameters.AddWithValue("@Supper", txtSupper.Text)
sqlFnB.Parameters.AddWithValue("@Snack", txtSnack.Text)
sqlFnB.Parameters.AddWithValue("@Beverage", txtBeverage.Text)
sqlFnB.Parameters.AddWithValue("@Grocerries", txtGroceries.Text)
sqlFnB.Parameters.AddWithValue("@SubFnB", txtSubFnB.Text)
sqlFnB.ExecuteNonQuery()

UpdatePCnI = "Update tblPersonalCareAndItems SET Medical_Fees = @Medical, Hair_Or_Nail = @HairNail, Clothing = @Cloth, Supplements = @Supplement, Soap_Or_Shampoo = @SoapShampoo, Facial_Cleanser = @Facial, Others = @PCnIOthers, Sub_Total = @SubPCnI WHERE Personal_Care_And_ItemsID = '" & LVDailyExpenses.DataGridView1.CurrentRow.Cells(0).Value.ToString & "' "
sqlPCnI = New SqlCommand(UpdatePCnI, connection)
sqlPCnI.Parameters.AddWithValue("@Medical", txtMedical.Text)
sqlPCnI.Parameters.AddWithValue("@HairNail", txtHairNail.Text)
sqlPCnI.Parameters.AddWithValue("@Cloth", txtClothing.Text)
sqlPCnI.Parameters.AddWithValue("@Supplement", txtSupplement.Text)
sqlPCnI.Parameters.AddWithValue("@SoapShampoo", txtSoapShampoo.Text)
sqlPCnI.Parameters.AddWithValue("@Facial", txtFacial.Text)
sqlPCnI.Parameters.AddWithValue("@PCnIOthers", txtPCnIOthers.Text)
sqlPCnI.Parameters.AddWithValue("@SubPCnI", txtSubPCnI.Text)
sqlPCnI.ExecuteNonQuery()

UpdateEntertainment = "Update tblEntertainment SET Video_Rental = @Video, Cinema = @Cinema, Concert = @Concert, Sport = @sport, Games = @games, Club_Bar_Disco = @clubbardisco, Others = @EntertainmentOthers, Sub_Total = @SubEntertainment WHERE EntertainmentID = '" & LVDailyExpenses.DataGridView1.CurrentRow.Cells(0).Value.ToString & "'"
sqlEntertainment = New SqlCommand(UpdateEntertainment, connection)
sqlEntertainment.Parameters.AddWithValue("@Video", txtVideo.Text)
sqlEntertainment.Parameters.AddWithValue("@Cinema", txtCinema.Text)
sqlEntertainment.Parameters.AddWithValue("@Concert", txtConcert.Text)
sqlEntertainment.Parameters.AddWithValue("@sport", txtSport.Text)
sqlEntertainment.Parameters.AddWithValue("@games", txtGames.Text)
sqlEntertainment.Parameters.AddWithValue("@clubbardisco", txtClubBarDisco.Text)
sqlEntertainment.Parameters.AddWithValue("@EntertainmentOthers", txtEntertainmentOthers.Text)
sqlEntertainment.Parameters.AddWithValue("@SubEntertainment", txtSubEntertainment.Text)
sqlEntertainment.ExecuteNonQuery()

UpdatePnO = "Update tblPaymentsAndOthers SET Phone_Bill = @phone, College_Fee_And_Misc = @college, Vehicle_Payment = @VP, Vehicle_License = @VL, Vehicle_Insurance = @VI, Credit_Card = @Credit, [Debit_Card] = @Debit, [Others] = @PnOOthers, Sub_Total = @SubPnO WHERE Payments_And_OthersID = '" & LVDailyExpenses.DataGridView1.CurrentRow.Cells(0).Value.ToString & "'"
sqlPnO = New SqlCommand(UpdatePnO, connection)
sqlPnO.Parameters.AddWithValue("@phone", txtPhoneBill.Text)
sqlPnO.Parameters.AddWithValue("@college", txtCollegeFeeAndMisc.Text)
sqlPnO.Parameters.AddWithValue("@VP", txtVehiclePayment.Text)
sqlPnO.Parameters.AddWithValue("@VL", txtVehicleLicense.Text)
sqlPnO.Parameters.AddWithValue("@VI", txtVehicleInsurance.Text)
sqlPnO.Parameters.AddWithValue("@Credit", txtCardCredit.Text)
sqlPnO.Parameters.AddWithValue("@Debit", txtDebitCard.Text)
sqlPnO.Parameters.AddWithValue("@PnOOthers", txtPnOOthers.Text)
sqlPnO.Parameters.AddWithValue("@SubPnO", txtSubPaymentnOthers.Text)

UpdateTransport = "Update tblTransportation SET [Bus_Fare] = @Bus, [Taxi_Fare] = @Taxi, [Train_Fare] = @Train, [Fuel] = @Fuel, [Maintainence] = @Maintain, [Others] = @TransOther, [Sub_Total] = @SubTransport WHERE TransportationID = '" & LVDailyExpenses.DataGridView1.CurrentRow.Cells(0).Value.ToString & "'"
sqlTransport = New SqlCommand(UpdateTransport, connection)
sqlTransport.Parameters.AddWithValue("@Bus", txtBusFare.Text)
sqlTransport.Parameters.AddWithValue("@Taxi", txtTaxiFare.Text)
sqlTransport.Parameters.AddWithValue("@Train", txtTrainFare.Text)
sqlTransport.Parameters.AddWithValue("@Fuel", txtFuel.Text)
sqlTransport.Parameters.AddWithValue("@Maintain", txtMaintainence.Text)
sqlTransport.Parameters.AddWithValue("@TransOther", txtTansportOthers.Text)
sqlTransport.Parameters.AddWithValue("@SubTransport", txtSubTransport.Text)
sqlTransport.ExecuteNonQuery()

UpdateHousing = "Update tblHousing SET [Rental] = @Rental, [Electricity] = @Electricity, [Water] = @Water, [Gas] = @Gas, [Supplies] = @Supplies, [Other] = @HousingOthers, [Sub_Total] = @SubHousing WHERE HousingID = '" & LVDailyExpenses.DataGridView1.CurrentRow.Cells(0).Value.ToString & "'"
sqlHousing = New SqlCommand(UpdateHousing, connection)
sqlHousing.Parameters.AddWithValue("@Rental", txtRental.Text)
sqlHousing.Parameters.AddWithValue("@Electricity", txtElectricity.Text)
sqlHousing.Parameters.AddWithValue("@Water", txtWater.Text)
sqlHousing.Parameters.AddWithValue("@Gas", txtGas.Text)
sqlHousing.Parameters.AddWithValue("@Supplies", txtSupplies.Text)
sqlHousing.Parameters.AddWithValue("@HousingOthers", txtHousingOthers.Text)
sqlHousing.Parameters.AddWithValue("@SubHousing", txtSubHousing.Text)
sqlHousing.ExecuteNonQuery()

UpdateLoan = "Update tblLoan SET [Personal] = @Personal, [Student] = @Student, [Business] = @Business, [Mortgage] = @Mortgage, [Others] = @LoanOthers, [Sub_Total] = @SubLoan WHERE LoanID = '" & LVDailyExpenses.DataGridView1.CurrentRow.Cells(0).Value.ToString & "'"
sqlLoan = New SqlCommand(UpdateLoan, connection)
sqlLoan.Parameters.AddWithValue("@Personal", txtPersonal.Text)
sqlLoan.Parameters.AddWithValue("@Student", txtStudent.Text)
sqlLoan.Parameters.AddWithValue("@Business", txtBusiness.Text)
sqlLoan.Parameters.AddWithValue("@Mortgage", txtMortgage.Text)
sqlLoan.Parameters.AddWithValue("@LoanOthers", txtLoanOthers.Text)
sqlLoan.Parameters.AddWithValue("@SubLoan", txtSubLoan.Text)
sqlLoan.ExecuteNonQuery()

UpdateLegal = "Update tblLegal SET [Attorney] = @Attorney, [Alimony] = @Alimony, [Summons] = @Summons, [Others] = @LegalOthers, [Sub_Total] = @SubLegal WHERE LegalID = '" & LVDailyExpenses.DataGridView1.CurrentRow.Cells(0).Value.ToString & "'"
sqlLegal = New SqlCommand(UpdateLegal, connection)
sqlLegal.Parameters.AddWithValue("@Attorney", txtAttorney.Text)
sqlLegal.Parameters.AddWithValue("@Alimony", txtAlimony.Text)
sqlLegal.Parameters.AddWithValue("@Summons", txtSummon.Text)
sqlLegal.Parameters.AddWithValue("@LegalOthers", txtLegalOthers.Text)
sqlLegal.Parameters.AddWithValue("@SubLegal", txtSubLegal.Text)


UpdateBanking = "Update tblBanking SET [Maybank_Balance] = @Maybank, [Maybank_Withdraw] = @MaybankW, [Maybank_Deposit] = @MaybankD, [CIMB_Balance] = @CIMB, [CIMB_Withdraw] = @CIMBW, [CIMB_Deposit] = @CIMBD, [Public_Bank_Balance] = @Public, [Public_Bank_Withdraw] = @PublicW, [Public_Bank_Deposit] = @PublicD, [Other_Bank_Balance] = @OtherBank, [Other_Bank_Withdraw] = @OtherBankW, [Other_Bank_Deposit] = @OtherBankD WHERE BankingID = '" & LVDailyExpenses.DataGridView1.CurrentRow.Cells(0).Value.ToString & "'"
sqlBanking = New SqlCommand(UpdateBanking, connection)
sqlBanking.Parameters.AddWithValue("@Maybank", txtMaybank.Text)
sqlBanking.Parameters.AddWithValue("@MaybankW", txtMaybankWithdraw.Text)
sqlBanking.Parameters.AddWithValue("@MaybankD", txtMaybankDeposit.Text)
sqlBanking.Parameters.AddWithValue("@CIMB", txtCIMB.Text)
sqlBanking.Parameters.AddWithValue("@CIMBW", txtCIMBWithdraw.Text)
sqlBanking.Parameters.AddWithValue("@CIMBD", txtCIMBDeposit.Text)
sqlBanking.Parameters.AddWithValue("@Public", txtPublicBank.Text)
sqlBanking.Parameters.AddWithValue("@PublicW", txtPublickBankWithdraw.Text)
sqlBanking.Parameters.AddWithValue("@PublicD", txtPublickBankDeposit.Text)
sqlBanking.Parameters.AddWithValue("@OtherBank", txtOtherBank.Text)
sqlBanking.Parameters.AddWithValue("@OtherBankW", txtOtherBankWithdraw.Text)
sqlBanking.Parameters.AddWithValue("@OtherBankD", txtOtherBankDeposit.Text)

UpdateExpenses = "Update tblExpenses SET [Date] = @Date, [Allowance] = @Allowance, [Total] = @Total, [Wallet] = @Wallet WHERE ExpensesID = '" & LVDailyExpenses.DataGridView1.CurrentRow.Cells(0).Value.ToString & "'"
sqlExpenses = New SqlCommand(UpdateExpenses, connection)
sqlExpenses.Parameters.AddWithValue("@Date", DateTimePicker1.Value)
sqlExpenses.Parameters.AddWithValue("@Allowance", txtAllowance.Text)
sqlExpenses.Parameters.AddWithValue("@Total", txtTotalUsage.Text)
sqlExpenses.Parameters.AddWithValue("@Wallet", txtWalletCash.Text)
MsgBox("Successfully Edited Expenses")
Call LVDailyExpenses.Fill_Data()
Me.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
connection.Close()
End Sub


Auto Calculation:
Quote:
Private Sub txtSubLegal_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSubLegal.TextChanged

If Not String.IsNullOrEmpty(txtSubLegal.Text) Then
If txtSubLegal.Text >= 0 Then
total_old = txtTotalUsage.Text

Total = SubFnB + SubEntertainment + SubPCnI + SubPnO + SubTransport + SubHousing + SubLoan + SubLegal
txtTotalUsage.Text = Total.ToString("#,###.00")

Wallet = txtWalletCash.Text
Wallet = (Wallet + total_old - Total)
txtWalletCash.Text = Wallet.ToString("#,###.00")
End If
End If
End Sub

Quote:
Private Sub txtPublickBankWithdraw_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPublickBankWithdraw.GotFocus
Old_PublicBank_Wthdraw = txtPublickBankWithdraw.Text
End Sub

Private Sub txtPublickBankWithdraw_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPublickBankWithdraw.LostFocus
If Not String.IsNullOrEmpty(txtPublickBankWithdraw.Text) Then
If IsNumeric(txtPublickBankWithdraw.Text) Then
Public_Bank_Balance = txtPublicBank.Text
Public_Bank_Withdraw = txtPublickBankWithdraw.Text

New_Publicbank_Balance = Public_Bank_Balance - Public_Bank_Withdraw + Old_PublicBank_Wthdraw
txtPublicBank.Text = New_Publicbank_Balance.ToString("#,###.00")

Wallet = txtWalletCash.Text
Wallet1 = Wallet + Public_Bank_Withdraw - Old_PublicBank_Wthdraw
txtWalletCash.Text = Wallet1.ToString("#,###.00")
Else
MsgBox("Please Fill In Numerical Value!")
txtPublickBankWithdraw.Text = Old_PublicBank_Wthdraw.ToString("#,###.00")
End If
End If

End Sub

GeneralRe: Update previous date data and then update the rest of the data Pin
David Mujica11-Sep-12 3:39
David Mujica11-Sep-12 3:39 
GeneralRe: Update previous date data and then update the rest of the data Pin
garyu8711-Sep-12 4:03
garyu8711-Sep-12 4:03 
Questionrelated dabase connectivity in vb6.0 Pin
sandy20506-Sep-12 18:28
sandy20506-Sep-12 18:28 
AnswerRe: related dabase connectivity in vb6.0 Pin
Eddy Vluggen6-Sep-12 18:36
professionalEddy Vluggen6-Sep-12 18:36 
QuestionVBA Script to update Active Directory Pin
DarrenAuchnie6-Sep-12 5:00
DarrenAuchnie6-Sep-12 5:00 
AnswerRe: VBA Script to update Active Directory Pin
Eddy Vluggen6-Sep-12 18:33
professionalEddy Vluggen6-Sep-12 18:33 
QuestionProblem With Datagridview Pin
sujuu6-Sep-12 0:39
sujuu6-Sep-12 0:39 
AnswerRe: Problem With Datagridview Pin
Eddy Vluggen6-Sep-12 18:31
professionalEddy Vluggen6-Sep-12 18:31 
Question.Net Control similar to Excel Text Wizard Pin
Member 77438055-Sep-12 14:54
Member 77438055-Sep-12 14:54 
AnswerRe: .Net Control similar to Excel Text Wizard Pin
Eddy Vluggen5-Sep-12 23:53
professionalEddy Vluggen5-Sep-12 23:53 
GeneralRe: .Net Control similar to Excel Text Wizard Pin
Member 77438056-Sep-12 2:32
Member 77438056-Sep-12 2:32 
GeneralRe: .Net Control similar to Excel Text Wizard Pin
Eddy Vluggen6-Sep-12 2:50
professionalEddy Vluggen6-Sep-12 2:50 
QuestionHow to Pass Parameter to Report Viewer ( vb.net 2010 ) ? Pin
sali224-Sep-12 20:58
sali224-Sep-12 20:58 
QuestionQuestion About this Function Pin
CHACAMAN3-Sep-12 11:30
CHACAMAN3-Sep-12 11:30 
AnswerRe: Question About this Function Pin
Dave Kreskowiak3-Sep-12 12:43
mveDave Kreskowiak3-Sep-12 12:43 
GeneralRe: Question About this Function Pin
CHACAMAN3-Sep-12 13:43
CHACAMAN3-Sep-12 13:43 
GeneralRe: Question About this Function Pin
CHACAMAN3-Sep-12 15:25
CHACAMAN3-Sep-12 15:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.