Solved

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

Posted on 2009-04-07
8
644 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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