Good day! The following code returns the first record in the recordset from the Test table:

... com.Connection = conn; com.CommandText = "Select * from Test"; OleDbDataReader myOleDbDataReader = com.ExecuteReader(); myOleDbDataReader.Read(); testDialog.textBox1.Text = myOleDbDataReader.GetString(1); testDialog.numericUpDown1.Value = myOleDbDataReader.GetInt32(2); testDialog.textBox2.Text = myOleDbDataReader.GetString(3); ... 

How to achieve that value returned on the cursor record, but not the first record of the table, without cycles?

    1 answer 1

    OleDbDataReader.Read returns bool . It returns true if the record is read, and false if the data set has ended. To work with this object, you need to organize a conditional loop, and make calls to the fields of the current row of the dataset inside the loop.

    In addition, the use of OleDbDataReader should be wrapped with a using block in order to free the connection in time.

    • Well, how to get the values ​​of the fields at the cursor (not the first, but the current record). In Delphi in this regard there is a good decision. How about c #. Reader wrote about it just to clarify the situation, if there is a solution without it, I will be glad to hear the answer. - IntegralAL
    • Where do you have a cursor? In MS Access or in your program with? - Modus
    • In the program with the grid - IntegralAL
    • Then you don’t need to reconnect at all, you need to refer to the grid and get its current line dataGridView1.CurrentRow.DataBoundItem As I recall, it is of type DataRowView , which has an indexer for accessing fields. - Modus
    • Thanks, I will try. The only question is how is the assignment of the value of a specific field? For example, how can textBox1.text assign the first column of a table? - IntegralAL