hello
I have a datareader and I how can i know that, how many row this datareader have?
string query_ci = "SELECT [Kolon1],[Kolon2],[Kolon3] FROM[Sheet6$A:J] WHERE [Kolon1]='" + kolon_bul+ "'";
OleDbDataReader rdr_ci;
OleDbCommand komut_ci = new OleDbCommand(query_ci, conn);
rdr_ci = komut_ci.ExecuteReader();
---> i want to know in here rows this "rdr_ci" have?
while (rdr_ci.Read())
{
---> or in here, i want to know in here how many times this "while" count in the first loop?
OleDbCommand komut = new
OleDbCommand("UPDATE [Sheet6$] SET [Cat]='OK' WHERE [Sira]='" + rdr_ci["Sira"] + "' ", baglanti);
komut.ExecuteNonQuery();
}
Loading
Suthish NairPosted Nov 5, 2010, 8:34 AM
not known until all the records have been read. You need to read all the records and keep track of count yourself.
Or as i listed above, use any of logics.
Or.. try..
DataTable dt = new DataTable();
dt.Load(rdr_ci);
dt.Tables[0].Rows.Count will gives the count..
JurePosted Nov 5, 2010, 8:57 AM
SELECT COUNT(*) AS NumOfRows FROM your_table
This will return single row with column named "NumOfRows". So now you just have to read the value from that single cell.
yokzuPosted Nov 5, 2010, 8:20 AM
Suthish NairPosted Nov 5, 2010, 8:14 AM
1. use two select queries, for count (ExecuteScalar) rows..
2. use Dataset logic
3. or from the same logic your using. you will get value from object "a".
oops you edited the post..
int a = 0;
check for HasRows
while loop
a++; ==> will gives number of rows..