I'm an old VB programmer trying to build an application in C#. Simple idea, really -- just want to have a cheesy form with 3 textboxes (populated from a database), and two buttons: Move Next and Move Previous.
In the old VB6 days I'd open a static connection on the Form_Load event, then open a recordset and populate my textboxes. My "Move Next" and "Move Previous" buttons would simply have "rst.MoveNext" and "rst.MovePrevious" code behind, along with something like [Textbox1.Text = rst("Field1")]. Then, finally on the Form's closing event, I'd have something like cnn.close.
From what I've read, this is not the way to do things in C#. Static database connections are taboo thanks to connection pooling. But this leaves some room for me to wonder: How do I redesign my little C# application without the static recordset and db connection?
If I open the connection, load the first record onto my form on the Load event (ie: SELECT TOP 1 FROM MYTABLE), then close the connection, how do I manage my MoveNext and MovePrevious buttons? Should I reopen the connection, and somehow try to query for the "Next Lowest" or "Next Highest" primary key in the table?
Or am I simply approaching this the wrong way entirely?
Any help is greatly appreciated!!!
Thanks, Jason