Hi all, just having problems with my next, previous, last and first buttons on my form. there not working but i am not sure where i am going wrong because i am a beginner. When i press any of the buttons it says 'there is no row at position 1' when there is on my datagridview and on my database as well.
Public Class Stock_Control
Dim dbConnection As OleDbConnection
Dim dbcommand As OleDbCommand
Dim dbdataAdapter As OleDbDataAdapter
Dim connectstring As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & "data source = COMP4.mdb"
Dim dtStockControl As DataTable
Dim inc As Integer
Dim MaxRows As Integer
Private Sub Stock_Control_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbConnection = New OleDbConnection(connectstring)
dbdataAdapter = New OleDbDataAdapter()
dtStockControl = New DataTable()
dbcommand = New OleDbCommand("Stock Control")
dbcommand.CommandType = CommandType.TableDirect
dbdataAdapter.SelectCommand = dbcommand
dbdataAdapter.SelectCommand.Connection = dbConnection
dbConnection.Open()
dbdataAdapter.Fill(dtStockControl)
grdStockControl.DataSource = dtStockControl
dbConnection.Close()
MaxRows = COMP4DataSet.Tables("Stock Control").Rows.Count
inc = -1
End Sub
Private Sub btnNextRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextRecord.Click
If inc <> MaxRows - 1 Then
inc = inc + 1
NavigateRecords()
Else
MsgBox("No More Rows")
End If
Private Sub btnPreviousRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreviousRecord.Click
If inc > 0 Then
inc = inc - 1
NavigateRecords()
Else
MsgBox("First Record")
End If
End Sub
Private Sub btnFirstRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirstRecord.Click
If inc <> 0 Then
inc = 0
NavigateRecords()
End If
End Sub
Private Sub btnLastRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLastRecord.Click
If inc <> MaxRows - 1 Then
inc = MaxRows - 1
NavigateRecords()
End If
Private Sub NavigateRecords()
'txtProductType.Text = COMP4DataSet.Tables("Stock Control").Rows(inc).Item(0)
'txtMake.Text = COMP4DataSet.Tables("Stock Control").Rows(inc).Item(1)
'txtPartNo.Text = COMP4DataSet.Tables("Stock Control").Rows(inc).Item(2)
'txtModel.Text = COMP4DataSet.Tables("Stock Control").Rows(inc).Item(3)
'txtWholesalerPrice.Text = COMP4DataSet.Tables("Stock Control").Rows(inc).Item(4)
'txtRetailPrice.Text = COMP4DataSet.Tables("Stock Control").Rows(inc).Item(4)
'txtSupplierUsed.Text = COMP4DataSet.Tables("Stock Control").Rows(inc).Item(6)
'txtQuantity.Text = COMP4DataSet.Tables("Stock Control").Rows(inc).Item(7)
'txtReOrderLevel.Text = COMP4DataSet.Tables("Stock Control").Rows(inc).Item(8)
End Sub
End Class