find the index of row in datatable,mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajeswari02
    New Member
    • Nov 2013
    • 8

    find the index of row in datatable,mysql

    hi,

    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.
    Code:
    using (MySqlConnection con = new MySqlConnection(ConnectionString))
                    {
                        String query = "select * from customer";
                        MySqlCommand command = new MySqlCommand(query, con);
                        MySqlDataAdapter da = new MySqlDataAdapter(query, con);
                        da.Fill(dt1);
                        totalRowsInDB = dt1.Rows.Count;
                        Startindex = dt1.Rows.IndexOf(dt1.Rows.Find(startNo));
                        Endindex = dt1.Rows.IndexOf(dt1.Rows.Find(endNo));
                        con.Open();
    here startNo=1002 and endNo=1005
    which i have in database primary key values
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    use:
    Code:
    select @a:=@a+1 ROWNUM, * from .....
    you can reset '@a' using:
    Code:
    set @a=0

    Comment

    Working...