Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL-Server Visual-Studio , +
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
 
Alessio
Posted 24-Aug-11 22:40pm

1 solution

Rate this: bad
good
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))
    {
    con.Open();
    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"]);
                }
            }
        }
    }
  Permalink  
Comments
alessio.gastaldo at 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
 
Alessio
OriginalGriff at 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 at 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
0 OriginalGriff 200
1 PIEBALDconsult 150
2 BillWoodruff 148
3 Jochen Arndt 135
4 DamithSL 130
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 25 Aug 2011
Copyright © CodeProject, 1999-2014
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