This simple Windows Forms application allows you to perform basic SQL database operations such as connecting to a database, retrieving records, counting records, and inserting records. It is a great starting point for learning how to work with databases in C# using the Windows Forms framework.
- Connection Test: Verify your database connection to ensure it's successful.
- Retrieve Records: Fetch records from the database and display them in a DataGridView.
- Count Records: Get the count of records in a table.
- Insert Records: Insert new records into the database.
Before you begin, make sure you have the following:
- Visual Studio or another C# development environment.
- SQL Server (SQL Express or other editions) installed on your machine.
- A SQL database (in this example, we're using the Northwind sample database).
-
Clone this repository to your local machine.
git clone https://github.com/yourusername/your-repo.git
-
Open the project in Visual Studio or your preferred C# development environment.
-
Build and run the application.
-
Connect to Database: On application startup, the program will attempt to connect to the Northwind database. The connection status will be displayed in the textbox labeled "Status."
-
Retrieve Records: Click the "Retrieve Records" button to fetch records from the "Customers" table in the Northwind database and display them in the DataGridView.
-
Count Records: Click the "Count Records" button to determine the number of records in the "Customers" table.
-
Insert Records: Enter values in the "CustomerID" and "CompanyName" textboxes, then click the "Insert Record" button to add a new customer to the "Customers" table.
If you encounter any issues with the application, please check the following:
- Ensure that you have SQL Server installed and running.
- Verify that you have the Northwind sample database installed, or adjust the connection string in the code to match your database.
Contributions are welcome! If you have ideas for improvements or new features, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Thanks to Microsoft for providing the Northwind sample database.
- This project was inspired by the need for a simple example of Windows Forms database integration.