Solution to connect V C# 2005 Exp to a local SQL database?  
Author Message
Coleby





PostPosted: Visual C# Express Edition, Solution to connect V C# 2005 Exp to a local SQL database? Top

would someone please advise how this can be done

What actually needs to be in the ADO Class. And once the ADO Class has been created do I need to call it in every form that I create

Thanks,

C



Visual Studio Express Editions41  
 
 
Scott McKeown





PostPosted: Visual C# Express Edition, Solution to connect V C# 2005 Exp to a local SQL database? Top

Hi Coleby,

If I understand you correctly what you need to do is add:

using System.Data.SqlClient - if you wish to use Microsoft SQL Server (inc Express Edition)

using System.Data.OleDB - if you wish to use Microsoft Access

using System.Data.OCDB - if you wish to use Orecal

Dont quote me on the spellings above I dont have a copy of C# with me at the moment, and you only need to include this onto the forms that are actualy using the data from your database

Hope this helps

Scott



 
 
Ancalagon





PostPosted: Visual C# Express Edition, Solution to connect V C# 2005 Exp to a local SQL database? Top

I don't know how are you making your data objects but I like to make them via code.
We'll go for the SqlServer option

add these to your code:
using System.Data.SqlClient;
using System.Data;

Then declare some private variables (just before the constructor of your form)
SqlConnection MyConnection;
SqlDataAdapter MyDataAdapter;
DataSet MyDataSet;

Then double click to your form and add this code:
MyConnection = new SqlConnection("<the connection string>");
MyDataAdapter = new SqlDataAdapter ("<Sql Command>", MyConnection);
MyDataSet = new DataSet();
MyDataAdapter.Fill(MyDataSet, "<The name you want for the table>");

And that's all.
you will need a ner DataAdapter for each different table but you can use the same dataset as long as in the .Fill() method of each DataAdapter you name the table with a different name
ah and for the connection string just go to www.connectionstrings.com (the insert link function doesn't seem to work under Firefox)

Now you have to remember some things if you use this method.
The security is quite weak so you should not send the connection string in that way... the recommendations you will see is that you should use an encrypted configuration file and that will help a lot in the security matter.

I hope you find this usefull... or at least I hope you can say "I now how not to do this" lol
... also I hope the answer didn't mess you up