Click here to Skip to main content
16,013,581 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Below Is My Code for Window Application :
VB.NET
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class frmTrialBalanceNew
    Dim objdb As New DataSave
    Protected Overrides ReadOnly Property CreateParams() As CreateParams
        Get
            Dim param As CreateParams = MyBase.CreateParams
            param.ClassStyle = param.ClassStyle Or &H200
            Return param
        End Get
    End Property
    Private Sub frmTrialBalanceNew_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            'Form is in center ---------------------------------------------
            MaximizeBox = False
            Dim boundWidth As Integer = Screen.PrimaryScreen.Bounds.Width
            Dim boundHeight As Integer = Screen.PrimaryScreen.Bounds.Height
            Dim x As Integer = boundWidth - Me.Width
            Dim y As Integer = boundHeight - Me.Height
            Me.Location = New Point(x / 2, y / 2)

            '---------------------------------------------------------------

            Dim purchase, exp As Double

            Dim datefrom As Date = frmTrialBalanceDate.DateFrom.Text
            lblDatefrom.Text = frmTrialBalanceDate.DateFrom.Text
            Dim Dateto As Date = frmTrialBalanceDate.DateTo.Text
            lblDateTo.Text = frmTrialBalanceDate.DateTo.Text
            purchase = Val(objdb.GetValue("select SUM(Amount) from tbl_StockTransaction where EntryType = 'Stock Purchase' and companyid = '" & strcompanyid & "' and EntryDate Between convert(datetime,'" & datefrom & "',103) and convert(datetime,'" & Dateto & "',103)"))
            exp = Val(objdb.GetValue("select SUM(Freight) + SUM(Labour) from PurchaseNew where PurchaseBillNo is not NULL and companyid = '" & strcompanyid & "' and PurchaseBillDate Between convert(datetime,'" & datefrom & "',103) and convert(datetime,'" & Dateto & "',103)"))
            lblPurchase.Text = Val(purchase) + Val(exp)
            'lblPurchase.Text = Val(objdb.GetValue("select SUM(Amount) from tbl_StockTransaction where EntryType = 'Stock Purchase' and companyid = '" & strcompanyid & "'"))

            lblOpeningStock.Text = Val(objdb.GetValue("select SUM(Amount) from tbl_StockTransaction where EntryType = 'Opening Stock' and companyid = '" & strcompanyid & "' and EntryDate Between convert(datetime,'" & datefrom & "',103) and convert(datetime,'" & Dateto & "',103)"))
            lblPurchaseReturn.Text = Val(objdb.GetValue("select SUM(Amount) from tbl_StockTransaction where EntryType = 'Purchase Return' and companyid = '" & strcompanyid & "' and EntryDate Between convert(datetime,'" & datefrom & "',103) and convert(datetime,'" & Dateto & "',103)"))
            lblTotalPurchase.Text = (Val(lblPurchase.Text) + Val(lblOpeningStock.Text)) - Val(lblPurchaseReturn.Text)
            lblCrgInwards.Text = Val(objdb.GetValue("select SUM(Labour) from SalesNew where InvoiceNO is Not NULL and companyid = '" & strcompanyid & "' and InvoiceDate Between convert(datetime,'" & datefrom & "',103) and convert(datetime,'" & Dateto & "',103)"))
            lblWages.Text = Val(objdb.GetValue("select SUM(Freight) from SalesNew where InvoiceNo is Not NULL and companyid = '" & strcompanyid & "' and InvoiceDate Between convert(datetime,'" & datefrom & "',103) and convert(datetime,'" & Dateto & "',103)"))

            'lblClosingStockAmount.Text = Val(objdb.GetValue("select SUM(Amount) from tbl_StockTransaction where companyid = '" & strcompanyid & "' and EntryDate Between '" & datefrom & "' and '" & Dateto & "'"))

            Dim ds As New DataSet
            Dim closingstock As Double = "0"
            ds = objdb.ReturnDS("select (SUM(B.Qty) * A.CostPrice) as [TotalAmount] from tbl_StockTransaction B,tbl_ItemMaster A where B.EntryDate Between convert(datetime,'" & datefrom & "',103) and convert(datetime,'" & Dateto & "',103) and A.ItemCode = B.ProductCode and B.companyid = '" & strcompanyid & "' group by A.CostPrice")
            For count = 0 To ds.Tables(0).Rows.Count - 1
                Dim totalamount As Double = ds.Tables(0).Rows(count)("TotalAmount")
                closingstock = closingstock + totalamount
            Next
            lblClosingStockAmount.Text = closingstock


            lblsales.Text = Val(objdb.GetValue("select SUM(AMount) from tbl_StockTransaction where EntryType = 'Stock Sell' and companyid = '" & strcompanyid & "' and EntryDate Between convert(datetime,'" & datefrom & "',103) and convert(datetime,'" & Dateto & "',103)"))
            lblsalesreturn.Text = Val(objdb.GetValue("select SUM(AMount) from tbl_StockTransaction where companyid = '" & strcompanyid & "'and EntryType = 'Sales Return' and EntryDate Between convert(datetime,'" & datefrom & "',103) and convert(datetime,'" & Dateto & "',103)"))
            lblTotalSales.Text = Val(lblsales.Text) + Val(lblsalesreturn.Text)


            Dim debitsidetotal, creditsidetotal As Double
            debitsidetotal = Val(lblTotalPurchase.Text) + Val(lblCrgInwards.Text) + Val(lblWages.Text)
            creditsidetotal = Val(lblClosingStockAmount.Text) + Val(lblTotalSales.Text)

            If debitsidetotal <= creditsidetotal Then
                lblTradingProfit.Text = Val(creditsidetotal) - Val(debitsidetotal)
                lblDrSideTotal.Text = Val(lblTradingProfit.Text) + Val(debitsidetotal)
                lblCrSideTotal.Text = creditsidetotal
                lblCRLoss.Visible = False
                lblCRPL.Visible = False
                lblDRPL.Visible = True
                lblDRProfit.Visible = True
                StrTrialBalance = lblTradingProfit.Text
            Else
                lblTradingLoss.Text = Val(debitsidetotal) - Val(creditsidetotal)
                lblDrSideTotal.Text = debitsidetotal
                lblCrSideTotal.Text = Val(lblTradingLoss.Text) + Val(creditsidetotal)
                lblCRLoss.Visible = True
                lblCRPL.Visible = True
                lblDRPL.Visible = False
                lblDRProfit.Visible = False
                StrTrialBalance = -lblTradingLoss.Text
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Try
            Me.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub
End Class


form Work Completely, When I Pres Close Button Give This Error.
VB.NET
Collection was modified; enumeration operation may not execute.


What I have tried:

Collection was modified; enumeration operation may not execute.
I am not using eny enumeration operation.
i am only use for loop and query
Posted
Comments
ZurdoDev 10-Feb-16 7:42am    
You have nothing in the close button code, except to close. You sure you're not getting the error when the form loads?
Richard Deeming 10-Feb-16 8:42am    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Sergey Alexandrovich Kryukov 10-Feb-16 11:25am    
In what line? What is unclear in this error message?
—SA

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