Solved

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

Posted on 2009-04-07
8
643 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

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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