Solved

VB.Net Custom BindingNavigator with SQL

Posted on 2013-10-23
4
764 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL STANDARD CORE 8 40
Generate Unique ID in VB.NET 21 67
SQL R 21 28
MS SQL Server select from Sub Table 14 26
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

830 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