By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 2,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

find the index of row in datatable,mysql

P: 8

i want to know the index of row( i know the primary key column value, based on that i want to know the index of that row in data table)

here is my code i tried:
but it's giving error as:table doesn't have a primary key. c#

But my datatable in Mysql database is having primary key column.
Expand|Select|Wrap|Line Numbers
  1. using (MySqlConnection con = new MySqlConnection(ConnectionString))
  2.                 {
  3.                     String query = "select * from customer";
  4.                     MySqlCommand command = new MySqlCommand(query, con);
  5.                     MySqlDataAdapter da = new MySqlDataAdapter(query, con);
  6.                     da.Fill(dt1);
  7.                     totalRowsInDB = dt1.Rows.Count;
  8.                     Startindex = dt1.Rows.IndexOf(dt1.Rows.Find(startNo));
  9.                     Endindex = dt1.Rows.IndexOf(dt1.Rows.Find(endNo));
  10.                     con.Open();
here startNo=1002 and endNo=1005
which i have in database primary key values
Mar 1 '14 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 1,035
Expand|Select|Wrap|Line Numbers
  1. select @a:=@a+1 ROWNUM, * from .....
you can reset '@a' using:
Expand|Select|Wrap|Line Numbers
  1. set @a=0
Mar 1 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.