3 Replies - 3358 Views - Last Post: 23 May 2011 - 03:06 AM Rate Topic: -----

#1 rjschu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 12-February 09

connecting to database in visual studio using c#

Posted 22 May 2011 - 04:16 PM

hi firstly id like to apologise if this question is in the wrong section.
im trying to learn c# using visual studio 2008 and im having trouble connecting a database i make in visual studio to my program the problem is i dont know what to put for the sqlconnection string as everything i do try comes up with an error

any help with this would be greatly appreciated.

thank you .
Is This A Good Question/Topic? 0
  • +

Replies To: connecting to database in visual studio using c#

#2 MATTtheSEAHAWK  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 137
  • View blog
  • Posts: 782
  • Joined: 11-September 10

Re: connecting to database in visual studio using c#

Posted 22 May 2011 - 04:38 PM

First take a look at this site and choose the type of connection string that you are using. Here is the link:
http://www.connectionstrings.com/

Here is the page on MSDN for it. Look at them and see if you can get anything from them.
http://msdn.microsof...tionstring.aspx

That's about all i can tell you because your post isn't the most detailed. If you get some more details on what you're doing then maybe we can help you a little more.
Was This Post Helpful? 1
  • +
  • -

#3 SurfingShark  Icon User is offline

  • D.I.C Head

Reputation: 38
  • View blog
  • Posts: 188
  • Joined: 18-April 11

Re: connecting to database in visual studio using c#

Posted 22 May 2011 - 06:39 PM

Please post your code.

Here's some logic:

1) Create your SqlConnection based off a connection string (from your web.config or an explicit string; the former is best practice)
2) Create a SqlCommand, and use the constructor to define your SqlConnection and CommandText (you can do this after the fact and use the parameterless constructor)
3a) For an UPDATE, DELETE, or INSERT command just open the connection and execute command
3b) For a SELECT statement you can use a SqlDataAdapter or SqlDataReader (each has their respective solutions)
4) Close the connection
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: connecting to database in visual studio using c#

Posted 23 May 2011 - 03:06 AM

And there are a bunch of tutorials right here that deal with DB access.

If you get an error, you need to copy and paste it EXACTLY as it appears in the Visual Studio environment.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1