locked
C# 3.0 - How to manage my DataBase? RRS feed

  • Question

  • Hi guys, I need an experienced opinion.

    Thanks in advance for any help,

    Aldo.

    Which one should be the best practice to manage connections / disconnections to databases, keeping the code fast, clean, secure and friendly to "end user" of the program?

    I am using both SQL Server and MS Access as databases.

    When interacting with the data through a DataGridView, the user/s may want to do one of the actions described below, (take in consideration that could be more than one user interacting with the same database at the same time).

    . - Read some data: I see no problem disregarding the possibility that the user may later want to update some data, so I think always initializing the DataGridView as read-only, and when user double click on it, trying to reopen the db (or table) exclusively. Is there any other possibility using OledbDataAdapter?

    . - Delete an entire existing row:  Since I cannot really delete information from my database (because the data is related to other tables) it's a kind of just updating the status of the data.

    . - Insert an entire new row: kind of update?

    . – Update some or lots of data (a few cells): First of all need to check if db or table is already exclusively open, if not, I think the question is updating the db after each change (double checking with user through message box in order to avoid errors) or updating the whole data when indicated by user through a button (without checking unintentional errors)?

    Every help will be useful.

    Tuesday, April 8, 2008 7:49 AM

Answers

  • Hi,

     

    I volunteer to give some INEXPERIENCED opinions. Most of these opinions are what I read from MSDN documents. I’ve been working with .NET and ADO.NET for a couple of months though. ^^

     

    Read some data: Most .NET Data Providers use a connection pool to store ready-to-use connection objects when a connection is required. Therefore, you don’t need to worry about the cost of establishing and closing the same connection for a couple of times you read data from the same data source.

     

    Data are pulled from the database and stored in a DataSet object in your application in an off-line manner. Query your data from the DataSet if you do not care about potential changes in the database.

     

    Delete a row: Just delete the row from the DataSet and update your bound control (for example, the DataGridView control). Changes are not reflected to the database as long as the DataSet.Update or DataAdapter.Update methods are not invoked.

     

    General information and guidelines can be found in this post: http://msdn2.microsoft.com/en-us/library/ss7fbaez.aspx

     

    Best regards,

    Jacob

    Monday, April 14, 2008 8:00 AM

All replies

  • Hi,

     

    I volunteer to give some INEXPERIENCED opinions. Most of these opinions are what I read from MSDN documents. I’ve been working with .NET and ADO.NET for a couple of months though. ^^

     

    Read some data: Most .NET Data Providers use a connection pool to store ready-to-use connection objects when a connection is required. Therefore, you don’t need to worry about the cost of establishing and closing the same connection for a couple of times you read data from the same data source.

     

    Data are pulled from the database and stored in a DataSet object in your application in an off-line manner. Query your data from the DataSet if you do not care about potential changes in the database.

     

    Delete a row: Just delete the row from the DataSet and update your bound control (for example, the DataGridView control). Changes are not reflected to the database as long as the DataSet.Update or DataAdapter.Update methods are not invoked.

     

    General information and guidelines can be found in this post: http://msdn2.microsoft.com/en-us/library/ss7fbaez.aspx

     

    Best regards,

    Jacob

    Monday, April 14, 2008 8:00 AM
  • Thanks man!

     

    Monday, April 14, 2008 8:19 AM