Resolved Connect to a Database and cycle through & edit records

Mark19

New member
Joined
Feb 25, 2021
Messages
3
Programming Experience
10+
I'm just starting with Visual Studio C#, and creating a windows forms app. I need to connect to an SQL Server Database and cycle through the records and make changes to the data, this is in the background and users don't need to see whats happening. I've got quite a lot of experience with VBa and would normally use ADODB recordset to achieve this. Is this the way to go in Visual C# or shall I investigate another method? I don't expect to be spoon fed just any pointers as to what methods to explore.
 
If this is all happening in the background, why the needed for a WinForms app? Why not a simple console app?

In general, if you are going batch processing like this, I recommend using ADO.NET to process records one at a time, instead of the RecordSet or it's .NET equivalent, DataSet, approach of reading in all the records into memory at once. What if you don't have enough memory to load all the records at once?
 
The WinForm app is needed for the user interface, I just need to manipulate a handful of records in a table when users make a specific selection and then clicks a button. There should always be enough memory as there will never be more than 50 records guaranteed, I will have a look into ADO.NET as you recommend. Thanks for the reply.
 
When you say VB, I assume that you mean VB6. You can use ADODB in VB.NET but you shouldn't. You should use ADO.NET in VB.NET just like you should in C#. The code is basically identical.

As you want to retrieve, edit, display and save data with SQL Server, I would suggest using a SqlDataAdapter to retrieve data from the database into a DataTable. You can then edit the rows of that DataTable as required, bind it to a DataGridView for display and then use the same SqlDataAdapter to save the changes back to the database. That is using ADO.NET, which is basically anything under System.Data and derived types.
 
When you say VB, I assume that you mean VB6. You can use ADODB in VB.NET but you shouldn't. You should use ADO.NET in VB.NET just like you should in C#. The code is basically identical.

As you want to retrieve, edit, display and save data with SQL Server, I would suggest using a SqlDataAdapter to retrieve data from the database into a DataTable. You can then edit the rows of that DataTable as required, bind it to a DataGridView for display and then use the same SqlDataAdapter to save the changes back to the database. That is using ADO.NET, which is basically anything under System.Data and derived types.
I mean VBa within Microsoft Access... I will have a look into SqlDataAdapters, thanks.
 
Back
Top Bottom