Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.Net Custom BindingNavigator with SQL

Posted on 2013-10-23
4
Medium Priority
?
794 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

916 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