Solved

How to connect, query using Visual C# and MS SQL

Posted on 2009-04-07
8
635 Views
Last Modified: 2013-12-17
I am trying to connecto to an MS SQL database that is defined in my Visual environment as (the connection) banking.sdf. In the Database explorer it shows all of the fields, etc. Yet, in the code I cannot connect. Can someone please show me how to do this with MS SQL? Obvisouly my code isn't even close so I won't post it here.
0
Comment
Question by:evault
8 Comments
 
LVL 7

Accepted Solution

by:
AUmidh earned 500 total points
Comment Utility
please have a look at it, might be it give you some help
http://www.homeandlearn.co.uk/csharp/csharp_s12p3.html
0
 
LVL 6

Expert Comment

by:SaedSalman
Comment Utility
Here is how to connect to database (with code):
http://www.daniweb.com/forums/thread21636.html

here is how to connect to database (wizard):
http://msdn.microsoft.com/en-us/library/bb655884.aspx

here is how to query database (Illustratation):

http://www.java2s.com/Code/CSharp/Database-ADO.net/IllustrateshowtoperformINSERTUPDATEandDELETEstatementsusingADONET.htm

here is how to query (Basic, tutorial and example):
http://www.codeproject.com/KB/database/simpledbreadwrite.aspx
0
 
LVL 1

Author Comment

by:evault
Comment Utility
Does not Visual C# have the ability to define the conenction outside of the code and keep it open? Or is that just for development purposes only?
0
 
LVL 1

Author Comment

by:evault
Comment Utility
I looked at the examples. I already have the connection open in the developer environment and can see the tables and even the data with the Database Explorer Tool and  the data Sources Tool. Should I already have open a persistent connection that I can then just query?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 26

Expert Comment

by:Anurag Thakur
Comment Utility
how can a connection be defined outside the code and then used
in the code you can create a connection for designer but when you actually release the application its not a presistant connection
it becomes active when the actual form on which that connection is defined is initialized or used

database explorer is just a utility which allows you to run queries on the database from the same window as your code.
its just a way from where you can see data and code in a same window rather than opening 2 separate windows
0
 
LVL 1

Author Comment

by:evault
Comment Utility
Kind of figured that out on my own. I've tried the site at http://www.homeandlearn.co.uk/csharp/csharp_s12p3.html; pretty cool. Got the connection working and everything but when I got to the part where I populate a form using the code from this page (http://www.homeandlearn.co.uk/csharp/csharp_s12p5.html) it gives me an error message during run time to the effect that I am trying to convert a string that has laready been converted. (I'll try to get the exact error message later tonight or tomorrow.
0
 
LVL 1

Author Comment

by:evault
Comment Utility
Got the problem figured out. Thanks to all of you.By the way, the HomandLearn site is a great web site.
0
 
LVL 1

Author Closing Comment

by:evault
Comment Utility
Thank you for assisting me with this. MS SQL is much different than MySQL and I can see I am going to need a lot of help.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now