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

Posted on 2009-04-07
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.
Question by:evault

Accepted Solution

AUmidh earned 500 total points
ID: 24089290
please have a look at it, might be it give you some help

Expert Comment

ID: 24090016
Here is how to connect to database (with code):

here is how to connect to database (wizard):

here is how to query database (Illustratation):

here is how to query (Basic, tutorial and example):

Author Comment

ID: 24090634
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?

Author Comment

ID: 24090680
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?
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

LVL 26

Expert Comment

by:Anurag Thakur
ID: 24093770
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

Author Comment

ID: 24094454
Kind of figured that out on my own. I've tried the site at; 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 ( 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.

Author Comment

ID: 24094776
Got the problem figured out. Thanks to all of you.By the way, the HomandLearn site is a great web site.

Author Closing Comment

ID: 31567606
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.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

24 Experts available now in Live!

Get 1:1 Help Now