Solved

VB.Net Custom BindingNavigator with SQL

Posted on 2013-10-23
4
755 Views
Last Modified: 2013-10-23
I am upgrading an access database to vb.net/sql winforms.  Our customers (Police Departments) have a large amount of data in their tables.  They also 'need' the ability to scroll through records.  In access this is simple, in .Net it poses a problem.

I was going to use Datatables with all the table data, however the amount of data would not only consume too much memory, it would be too slow upon startup.

I decided to 'customize' the bindingnavigator.  The datatable(s) will hold only the first 100 records and I would also have a 'RecordPointer' where upon if the user scrolls to record 101, it will then clear out the datatable, load the next 100 records and rebind.  It seems to be working ok for the most part, however I am having a few issues.

When going past record 100, then scrolling back, it reloads the datatable but it not going back more than one record.  Here is a sample of my code that I have, maybe one of you wizards can help me on this?

Form load:


Public RecordPointer As Integer = 0
 Public Sub New()
        Try

Dim qryCreateTableCS As New SqlCommand("SELECT * FROM  (SELECT ROW_NUMBER()  OVER (ORDER BY IncnoID DESC) AS Row, *,CONVERT(VARCHAR, TimeComp, 108) AS newTimeComp,CONVERT(VARCHAR, Dispatched, 108) AS newDispatched,CONVERT(VARCHAR, Arrived, 108) AS newArrived,CONVERT(VARCHAR, TimeClear, 108) AS newTimeClear,CONVERT(VARCHAR, OtherTime, 108) AS newOtherTime FROM CALLSERV) AS CS WHERE Row BETWEEN 1 AND 99", connection)

            adapter.SelectCommand = qryCreateTableCS
            adapter.Fill(SPISDataSet, "dtCallServ")
 CSBindingSource1.DataSource = SPISDataSet.Tables("dtCallServ")

            BindingNavigator1.BindingSource = CSBindingSource1
 Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
End Sub

Private Sub btnNextRecord_Click(sender As Object, e As EventArgs) Handles btnNextRecord.Click
        RecordPointer = RecordPointer + 1

        If RecordPointer Mod 100 = 0 Then
            GetNextRecord()
        Else
            CSBindingSource1.MoveNext()
            Application.DoEvents()
            txtCurrentRecord.Text = txtCurrentRecord.Text + 1
        End If
    End Sub
Private Sub GetNextRecord()
        Dim cmd As SqlCommand
        Dim sql As String

        Dim qryCreateTableCS As New SqlCommand("SELECT * FROM  (SELECT ROW_NUMBER()  OVER (ORDER BY IncnoID DESC) AS Row, *,CONVERT(VARCHAR, TimeComp, 108) AS newTimeComp,CONVERT(VARCHAR, Dispatched, 108) AS newDispatched,CONVERT(VARCHAR, Arrived, 108) AS newArrived,CONVERT(VARCHAR, TimeClear, 108) AS newTimeClear,CONVERT(VARCHAR, OtherTime, 108) AS newOtherTime FROM CALLSERV) AS CS WHERE Row BETWEEN " & RecordPointer & " AND " & RecordPointer + 100, connection)

        SPISDataSet.Tables("dtCallServ").Clear()
        Application.DoEvents()

        adapter.SelectCommand = qryCreateTableCS
        adapter.Fill(SPISDataSet, "dtCallServ")

        CSBindingSource1.DataSource = SPISDataSet.Tables("dtCallServ")
         Application.DoEvents()
    End Sub
    Private Sub btnPreviousRecord_Click(sender As Object, e As EventArgs) Handles btnPreviousRecord.Click
        If RecordPointer > 1 Then
            RecordPointer = RecordPointer - 1

            If RecordPointer Mod 100 = 0 Then
                GetPreviousRecord()
            Else
                CSBindingSource1.MovePrevious()
                Application.DoEvents()
                txtCurrentRecord.Text = txtCurrentRecord.Text - 1
            End If
        End If
    End Sub

    Private Sub GetPreviousRecord()
        Dim cmd As SqlCommand
        Dim sql As String

        Dim qryCreateTableCS As New SqlCommand("SELECT * FROM  (SELECT ROW_NUMBER()  OVER (ORDER BY IncnoID DESC) AS Row, *,CONVERT(VARCHAR, TimeComp, 108) AS newTimeComp,CONVERT(VARCHAR, Dispatched, 108) AS newDispatched,CONVERT(VARCHAR, Arrived, 108) AS newArrived,CONVERT(VARCHAR, TimeClear, 108) AS newTimeClear,CONVERT(VARCHAR, OtherTime, 108) AS newOtherTime FROM CALLSERV) AS CS WHERE Row BETWEEN " & RecordPointer - 100 & " AND " & RecordPointer & " ORDER BY Incno ASC", connection)

        SPISDataSet.Tables("dtCallServ").Clear()
        Application.DoEvents()

        adapter.SelectCommand = qryCreateTableCS
        adapter.Fill(SPISDataSet, "dtCallServ")

        CSBindingSource1.DataSource = SPISDataSet.Tables("dtCallServ")
        Application.DoEvents()
    End Sub

Open in new window

0
Comment
Question by:K-9
  • 3
4 Comments
 

Author Comment

by:K-9
ID: 39594112
I found out why it's only going to the first record, when I go past 100 and then back below, its because of my query.  I actually have to do a 'MoveNext' instead of a 'MovePrevious' if I am going backwards.  However, I need to figure out to only doing this when I am not in my first set of 100 records.

I can't query to see if a IncnoID is within' the first 100 records since larger PDs can use 100 records within a short period of time.  Any ideas?
0
 

Accepted Solution

by:
K-9 earned 0 total points
ID: 39594147
I was able to get it, I set a public variable that just increments on movenext and decrements on moveprevious.

 RecordPointer = RecordPointer - 1
        If RecordPointer Mod 100 = 0 Then
            GetPreviousRecord()
        Else
            If RecordPointer > 0 And RecordPointer < 100 Then
                CSBindingSource1.MoveNext()
            Else
                CSBindingSource1.MovePrevious()
                Application.DoEvents()
            End If
        End If

        txtCurrentRecord.Text = txtCurrentRecord.Text - 1

Open in new window

0
 

Author Closing Comment

by:K-9
ID: 39594148
Was able to resolve it myself.
0
 
LVL 21
ID: 39594561
Thanks for sharing your solution!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now