Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-07
8
Medium Priority
?
646 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 2000 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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

721 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