I believe this is a very novice question, and if I'm using the wrong forum to ask, please advise.
I have a basic understanding of databasing with MS SQL Server, and programming with C++ and C#. I'm trying to teach myself more by setting up my own database with MS SQL Server Express 2008 R2 and accessing it via Windows forms created in C# Express 2010. At this point, I just want to keep it to free or Express dev tools (not necessarily Microsoft though).
Anyway, I created a database using the instructions provided here and I set the data types appropriately for each column (no errors in setup at least).
Now I'm designing the GUI in C# Express but I've kind of hit a wall as far as the database connection.
Is there a simple way to access the database I created locally using C# Express? Can anyone suggest a guide that has all this spelled out already?
I am a self-learner so I look forward to teaching myself how to use these applications, but any pointers to start me off in the right direction would be greatly appreciated.
You will need to import the following namespaces. Inside the Form Initialize event handler, BindGrid method is called. Inside BindGrid method, first a connection to the database is established using the SqlConnection class and then the SqlCommand is initialized with the SQL to be executed.
I'd start by taking a look at this tutorial:
http://msdn.microsoft.com/en-us/library/ms178371.aspx
The basic ideas is to create a connection string that will define a number of things, including: where your db server is, what the database name is, and how you are connecting to it.
Once you have your connection string defined you will probably use the SqlConnection, SqlCommand and SqlDataReader classes for all interactions with the database. If you click on the links for those three classes and look at the documentation you will see they have pretty good examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With