Hi, I am Ahmed,
I am using wampserver 2.0 with other default components(php, mysql, etc) in windows 7 32 bit machine. Whe I connecting to wampserver through an offline desktop application it works fine. But when i running a query via another form in same application, it takes huge time to execute. Sometimes not responding. Is there any way to solve this ?
targeting table contains 42 fields with 300,000 of records
followings are the statements.
For n = 0 To size
accCode = Me.ListBox1.Items(n) ' available account codes is in listbox
Me.dgvData.Rows.Add()
m = m + 1
Me.dgvData.Rows(m).Cells(1).Value = accCode + "_" + fun.accountName(accCode)
For j = 1 To 12
If j < 10 Then
fromDate = Me.dtpAMonth.Text + "-0" + j.ToString + "-" + "01 00:00:00"
toDate = Me.dtpAMonth.Text + "-0" + j.ToString + "-" + Date.DaysInMonth(Me.dtpAMonth.Text, j).ToString + " 23:59:59"
Else
fromDate = Me.dtpAMonth.Text + "-" + j.ToString + "-" + "01 00:00:00"
toDate = Me.dtpAMonth.Text + "-" + j.ToString + "-" + Date.DaysInMonth(Me.dtpAMonth.Text, j).ToString + " 23:59:59"
End If
'Me.dgvData.Rows(m).Cells(j + 1).Value = debitSumOfAnAccount(accCode, fromDate, toDate) - creditSumOfAnAccount(accCode, fromDate, toDate)
Me.dgvData.Rows(m).Cells(j + 1).Value = fun.sumOfAnDebitAccountInAPeriod(accCode, fromDate, toDate)
GC.Collect()
Me.Refresh()
Next
Next
function of "sumOfAnDebitAccountInAPeriod"
Dim SQLStatement As String = "SELECT debitorcredit, amount FROM account_accountsbalance_tb WHERE accountcode = '" + accCode + "' AND dateandtime BETWEEN '" + fromDate + "' AND '" + fromTo + "'"
Dim tempDebitOrCredit As String = ""
Dim tempTotal As Double = 0.0
Dim SQLConnection As MySqlConnection = New MySqlConnection
Dim cmd As MySqlCommand = New MySqlCommand
Dim rdr As MySqlDataReader
Try
SQLConnection.ConnectionString = ServerString
SQLConnection.Open()
cmd.CommandText = SQLStatement
cmd.CommandType = CommandType.Text
cmd.Connection = SQLConnection
cmd.ExecuteNonQuery()
rdr = cmd.ExecuteReader()
While (rdr.Read())
tempDebitOrCredit = rdr("debitorcredit")
If tempDebitOrCredit = "Debit" Then
tempTotal = tempTotal + Double.Parse(rdr("amount"))
ElseIf tempDebitOrCredit = "Credit" Then
tempTotal = tempTotal - Double.Parse(rdr("amount"))
End If
End While
rdr.Close()
Catch ex As Exception
toLogFile("", "sumOfAnDebitAccountInAPeriod-Exception", Now.ToString("yyyy-MM-dd HH:mm:ss"))
recordExceptionalError("sumOfAnDebitAccountInAPeriod(Function) - Account_ProfitAndLossStatment", ex.Message.ToString, Now.ToString("yyyy-MM-dd HH:mm:ss"))
MessageBox.Show(ex.Message + " Error while calculating sum of an debit account.", "ABC MAS 1.5", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
SQLConnection.Close()
SQLConnection.Dispose()
cmd.Dispose()
GC.Collect()
End Try
Return tempTotal
I am using wampserver 2.0 with other default components(php, mysql, etc) in windows 7 32 bit machine. Whe I connecting to wampserver through an offline desktop application it works fine. But when i running a query via another form in same application, it takes huge time to execute. Sometimes not responding. Is there any way to solve this ?
targeting table contains 42 fields with 300,000 of records
followings are the statements.
For n = 0 To size
accCode = Me.ListBox1.Items(n) ' available account codes is in listbox
Me.dgvData.Rows.Add()
m = m + 1
Me.dgvData.Rows(m).Cells(1).Value = accCode + "_" + fun.accountName(accCode)
For j = 1 To 12
If j < 10 Then
fromDate = Me.dtpAMonth.Text + "-0" + j.ToString + "-" + "01 00:00:00"
toDate = Me.dtpAMonth.Text + "-0" + j.ToString + "-" + Date.DaysInMonth(Me.dtpAMonth.Text, j).ToString + " 23:59:59"
Else
fromDate = Me.dtpAMonth.Text + "-" + j.ToString + "-" + "01 00:00:00"
toDate = Me.dtpAMonth.Text + "-" + j.ToString + "-" + Date.DaysInMonth(Me.dtpAMonth.Text, j).ToString + " 23:59:59"
End If
'Me.dgvData.Rows(m).Cells(j + 1).Value = debitSumOfAnAccount(accCode, fromDate, toDate) - creditSumOfAnAccount(accCode, fromDate, toDate)
Me.dgvData.Rows(m).Cells(j + 1).Value = fun.sumOfAnDebitAccountInAPeriod(accCode, fromDate, toDate)
GC.Collect()
Me.Refresh()
Next
Next
function of "sumOfAnDebitAccountInAPeriod"
Dim SQLStatement As String = "SELECT debitorcredit, amount FROM account_accountsbalance_tb WHERE accountcode = '" + accCode + "' AND dateandtime BETWEEN '" + fromDate + "' AND '" + fromTo + "'"
Dim tempDebitOrCredit As String = ""
Dim tempTotal As Double = 0.0
Dim SQLConnection As MySqlConnection = New MySqlConnection
Dim cmd As MySqlCommand = New MySqlCommand
Dim rdr As MySqlDataReader
Try
SQLConnection.ConnectionString = ServerString
SQLConnection.Open()
cmd.CommandText = SQLStatement
cmd.CommandType = CommandType.Text
cmd.Connection = SQLConnection
cmd.ExecuteNonQuery()
rdr = cmd.ExecuteReader()
While (rdr.Read())
tempDebitOrCredit = rdr("debitorcredit")
If tempDebitOrCredit = "Debit" Then
tempTotal = tempTotal + Double.Parse(rdr("amount"))
ElseIf tempDebitOrCredit = "Credit" Then
tempTotal = tempTotal - Double.Parse(rdr("amount"))
End If
End While
rdr.Close()
Catch ex As Exception
toLogFile("", "sumOfAnDebitAccountInAPeriod-Exception", Now.ToString("yyyy-MM-dd HH:mm:ss"))
recordExceptionalError("sumOfAnDebitAccountInAPeriod(Function) - Account_ProfitAndLossStatment", ex.Message.ToString, Now.ToString("yyyy-MM-dd HH:mm:ss"))
MessageBox.Show(ex.Message + " Error while calculating sum of an debit account.", "ABC MAS 1.5", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
SQLConnection.Close()
SQLConnection.Dispose()
cmd.Dispose()
GC.Collect()
End Try
Return tempTotal