Solved

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

Posted on 2009-04-07
8
642 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 7

Accepted Solution

by:
AUmidh earned 500 total points
ID: 24089290
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
ID: 24090016
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
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?
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 1

Author Comment

by:evault
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?
0
 
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
0
 
LVL 1

Author Comment

by:evault
ID: 24094454
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
ID: 24094776
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
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

762 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