How to create a simple Windows form to access a SQL Server database?

I believe this is a very newbie, and if I use the wrong forum for discussion, please let us know.

I have a basic understanding of a database with MS SQL Server and programming in C ++ and C #. I'm trying to educate myself more by setting up my own database with MS SQL Server Express 2008 R2 and accessing it through Windows forms created in C # Express 2010. At this point, I just want this to release or redistribute tools for developers ( for example, not necessarily Microsoft, though).

In any case, I created the database using the instructions given here , and I set the data types for each column accordingly (no configuration errors at least).

Now I'm designing a graphical interface in C # Express, but I kind of hit the wall as I connected to the database.

Is there an easy way to access a database that I created locally using C # Express? Can anyone suggest a guide in which all this has already been spelled out?

I am self-employed, so I look forward to learning how to use these applications, but we would really like all the pointers to start me in the right direction.

+6
c # sql-server sql-server-express winforms
source share
4 answers

I would start by learning this lesson:

http://msdn.microsoft.com/en-us/library/ms178371.aspx

Key ideas: create a chain that defines a number of things, including: where is your db server located, what is the database name and how to connect to it.

Once you have the connection string installed, you are likely to use SqlConnection , SqlCommand, and SqlDataReader for all database interactions. If you click on the links for these three classes and look at the documentation, you will see that they have pretty good examples.

+4
source share

You probably want to use the old ADO.NET school if you are more comfortable with SQL than C #.

MSDN entry into ADO.NET

+2
source share

Far and easiest way to do this with LINQ in Visual Studio

You may want to read this guide, which will help you complete all the necessary steps.

http://www.codegod.de/WebAppCodeGod/tutorial-linq-to-sql---part-1-AID466.aspx

+2
source share

its simple

use the following code

SqlConnection con = new SqlConnection(@"server=.\SQLEXPRESS;AttachDbFilename=path of database file;Integrated Security=True;User Instance=True"); 
0
source share

All Articles