Search code examples
c#visual-studio-2008database-connectivity

How To Establish A Connection To Database Using C# Application?


Im using Visual Studio 2008 . and wants to connect to database. My Application (in C#) is to develop a form acts like Image Viewer and to perform insert an image and delete an image , Also To Display the images In Database


Solution

  • Assuming that your DBMS is Sql server. You could do for example

    SqlConnection conn = new SqlConnection("connString here");//conn string here
    conn.Open();//if using SqlDataReader
    SqlCommand cmd = new SqlCommand("your query", conn);///your command object
    ....
    .....
    

    In order to insert the image to the database, there are mainly two options, either to save the image path in the database or save the image itself in database as BLOB.