SQL Datareader search

thomasgeorgem

Newcomer
Joined
Aug 17, 2009
Messages
4
Hi,

I am using SQL datareader object to open a recordset and browse through it.

my purpose is to search for a particular row with a specific column value.
In VB.6 I was using recordset.find method or recordset.filter property.

Is there any equivalent in VB.net ?

thanks in advance.

Thomas
 
Last edited:
The datareader class is similar to a VB6 ADODB.Recordset with the cursortype set to adOpenForwardOnly and the locktype set to adLockReadOnly. So, basically you can only loop through the records from first to last. No backwards scrolling, Find or filter is available.

How many times do you perform the find or filter on the recordset? I try to use a datareader for each Find or Filter call.
 
I can write this quicker using C# (what I'm accustomed to):
Code:
DataTable GetTable(string sqlSelectStatement, string connectionString) {
  DataTable table = new DataTable();
  SqlConnection con = new SqlConnection(connectionString);
  SqlCommand cmd = new SqlCommand(con, sqlSelectStatement);
  cmd.Connection.Open();
  SqlDataReader r = cmd.ExecuteReader();
  table.Load(r);
  cmd.Connection.Close();
  return table;
}
The code above has bad form and does zero error checking, though.

Once you have the DataTable, you can get the info you want out of it.
 
Back
Top