Move to a next record using ado.net
How can i create a command that can use a ado.net to move in a next record using stored procedure with parameters.
I am using a sql 2005.
Last edited by ryoka012; 06-14-2012 at 6:31 AM.
It depends exactly what you mean by moving to the next record. With ADO.NET, there are basically three ways to work with your data:
1. Call ExecuteReader on your command object to create a data reader, then call Read on that data reader in a loop to read the result set of your query row by row. A data reader is read-only and forward-only, so if you want to be able to use the data again later, you need to store it somewhere yourself.
2. After calling ExecuteReader, you can pass the data reader to the Load method of a DataTable to load the result set into that DataTable. You can then use that DataTable in whatever way you like.
3. If you want to edit and save the data then you should use a data adapter to populate a DataTable by calling its Fill method. After editing the data as required, you can call Update on the data adapter to save the changes.
If you choose one of the options that involves a DataTable, you can bind it to a BindingSource and bind that to a DataGridView or individual TextBoxes, etc. The BindingSource exposes all the rows as a list and the selected row via its Current property. You can navigate the data using the MoveFirst, MovePrevious, MoveNext and MoveLast methods. You can also associate the BindingSource with a BindingNavigator, which is a specialised ToolStrip with buttons for each of those methods and more.
Thanks jmcilhinney got it now.