How to show data in lable with Dataset? RRS feed

  • Question

  • Hi all
    I'm new in ADO.net.
    I have a windows form with Datagrid and lable.I can show data from database in my datagrid but i want to show data in my lable .that means when i scroll my datagrid ,for xample name field of each rows show in lable .how can i do that?
    here is my code but it doesnt work correctly
    Code Snippet

    SqlConnection con=new SqlConnection("......");
    SqlDataAdapter adaptor=new SqlDataAdapter("SELECT * FROM Info",con);
    DataSet ds=new DataSet();
    label1.Text = ds.Tables["Table_Info"].Columns["name"].Tostring();

    Thank you
    Tuesday, April 15, 2008 6:05 PM


  • First, You'll need to get the index of the currently selected record.




    Code Snippet


    int currentIndex = dataGridView1.CurrentRow.Index

    label1.Text = ds.Tables["Table_Info"].Rows[currentIndex]["name"].Tostring();





    Hope this helps...


    Tuesday, April 15, 2008 8:36 PM