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 .
connecting to database in visual studio using c#
Page 1 of 13 Replies - 1746 Views - Last Post: 23 May 2011 - 03:06 AM
Replies To: connecting to database in visual studio using c#
#2
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.
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.
#3
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
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
#4
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.
If you get an error, you need to copy and paste it EXACTLY as it appears in the Visual Studio environment.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|