Question Not able to retrieve the last record

cheenarao

New member
Joined
Feb 22, 2014
Messages
2
Programming Experience
1-3
Hi All,

I am trying to retrieve the last record updated by the user in the windows application, the code that I am using is

VB.NET:
Dim objconnection As New OleDbConnection        Dim cmdOledb As New OleDbCommand
        Dim objcmd As New OleDbCommand
        Dim cmdInsert As New OleDbCommand
        'Dim strsql As String
        Dim dbconn As New OleDbConnection
        'Dim last As Char
      dbconn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Srinivas_rao_n\Documents\Ideation.accdb;")
        dbconn.Open()
    cmdOledb.CommandText = "select max(rec_id) from idea"
       cmdOledb.Connection = dbconn
        Dim rdroledb As OleDbDataReader = cmdOledb.ExecuteReader
     Label3.Text = rdroledb.Item(0).ToString

There is an error message as Invalid Exception was handled "No data exists for the row/column", row (Rec_ID) is an auto number. The data insertion is good but the retrieval is a problem Please help me in resolving the query.

Thanks in advance.
 
A data reader only exposes one record at a time. To advance to the next record, you must call Read. To begin with, the data reader doesn't expose any record and you must call Read to advance to the first record.

That said, you shouldn't be calling ExecuteReader anyway. You're only retrieving a single value and that's exactly what ExecuteScalar exists for.

By the way, why is your code declaring three OleDbCommand variables and two OleDbConnection variables? Isn't one of each enough?
 
Thank u very much, it worked.

I have a new problem now, I am trying to retrieve the data in the form of a table (Grid View), but I am confused as how to get a particular data.
For Ex. There is a text box where the end user will type in the Acknowledge no. and the data has to be retrieved, but when I add the data grid and connect to the database all the records will be displayed. Please help me on that.

Thanks in Advance.
 
Thank u very much, it worked.

I have a new problem now, I am trying to retrieve the data in the form of a table (Grid View), but I am confused as how to get a particular data.
For Ex. There is a text box where the end user will type in the Acknowledge no. and the data has to be retrieved, but when I add the data grid and connect to the database all the records will be displayed. Please help me on that.

Thanks in Advance.

If the original problem is solved then please mark this thread as Resolved and start a new thread for the new topic.
 
Back
Top