Click here to Skip to main content
13,057,089 members (43,798 online)
Rate this:
Please Sign up or sign in to vote.
Hi all,

I've a problem with my project in c#, specifically with the creation of a database and the interaction with it. I would like some tips and guidelines.
Starting with the kind of db:
-)premise that the bulk of my data is quite small, wich kind of database should I create? (I prefer work with no local database, and sql server)

Let's connection with the project: how should i connect my project with the database? Could someone give me some guidelines, and some code's example?

Thanks in advance to all

Posted 24-Aug-11 21:40pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you have SQL Server, then use an SQL server database. Unless you are going to be distributing your application, and each instance will use the DB as a standalone store, in which case SQL server is a bit overkill. Then I would use SQLCE or SQLite instead.
For SQL server databases:
using (SqlConnection con = new SqlConnection(strCon))
    string strcmd = "SELECT fileName FROM myTable WHERE iD=@ID";
    using (SqlCommand cmd = new SqlCommand(strcmd, con))
        cmd.Parameters.AddWithValue("@ID", iD);
        using (SqlDataReader r = cmd.ExecuteReader())
            while (r.Read())
                Console.Write((string) r["fileName"]);
alessio.gastaldo 25-Aug-11 7:19am
Thanks for the help! I've another answer, sorry.
How have you composed the string strCon? Could you give me an example?

Thanks in advance

OriginalGriff 25-Aug-11 7:27am
strCon is just the straight connection string needed to access the database - I read it directly from web.config or by application configuration as appropriate. Mine would be no use to you at all! :laugh:
If you need to find out what your string is:
1) In Visual Studio, open the Server Explorer pane
2) Connect to your database, and highlight it in the Server Explorer pane.
3) The properties pane will have your connection string, and you can copy and paste it from there.
alessio.gastaldo 25-Aug-11 7:41am
Thanks I'll try to follow your tips!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170728.6 | Last Updated 25 Aug 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100