Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.Net Custom BindingNavigator with SQL

Posted on 2013-10-23
4
Medium Priority
?
785 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

719 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