Results 1 to 4 of 4

Thread: How to Connect Database and Retrieve it with the use of C#?

  1. #1
    Join Date
    Nov 2008
    Posts
    68

    How to Connect Database and Retrieve it with the use of C#?

    Hi friends I am a student of BSC.I.T. and wanted to know how to connect and retrieve database with the help of C#. We don't have that much in syllabus and want to know how to do it? If anyone has knowledge please help me. I am waiting for your reply. Just provide me steps or code so I can understand it.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to Connect Database and Retrieve it with the use of C#?

    Hi, you can use following code to connect database in c#

    Code:
    public void ConnectToAccess()
    {
    System.Data.OleDb.OleDbConnection conn = new
    System.Data.OleDb.OleDbConnection();
    database. conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data source= @"path \AccessFile.mdb";
    try
    {
    conn.Open();
    // Just insert here your code to process data
    catch (Exception caught)
    {
    MessageBox.Show(caught.Message);
    }
    finally
    {
    conn.Close();
    }
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: How to Connect Database and Retrieve it with the use of C#?

    Hi friend, I am also facing same problem as you, I have tried to search this on net, but not get anything regarding this. If you find something regarding this then suggest me also. I am waiting for you to reply me. I will search for this and if find something then I will give it to you. Just give me if you got earlier that me. Just post on this forum. I will take it as I am always using this forum for my queries.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to Connect Database and Retrieve it with the use of C#?

    Hi, Just use following for your making connection as a code, I think this would help you.

    Code:
    database. conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=AccessFile.mdb";
    If you want to connect in other languages then use following code:

    Visual Basic:
    Code:
    Public Sub CreateSqlConnection()
    Dim myConnection As New SqlConnection()
    myConnection.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30"
    myConnection.Open()
    End Sub 'CreateSqlConnection
    C#:
    Code:
    public void CreateSqlConnection()
    {
    SqlConnection myConnection = new SqlConnection();
    myConnection.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30";
    myConnection.Open();
    }
    C++:
    Code:
    public:
    void CreateSqlConnection()
    {
    SqlConnection* myConnection = new SqlConnection();
    myConnection->ConnectionString = S"Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30";
    myConnection->Open();
    }

Similar Threads

  1. Using Ajax to Retrieve Data from a MySQL Database
    By warthogweb in forum Software Development
    Replies: 1
    Last Post: 19-11-2010, 10:46 PM
  2. How to connect ASP to different database
    By Elijah2010 in forum Software Development
    Replies: 5
    Last Post: 16-02-2010, 12:01 AM
  3. how to connect VB6 to database
    By WILTON in forum Software Development
    Replies: 3
    Last Post: 08-12-2009, 04:26 AM
  4. How to Connect a database (MDB) to excel
    By Rebeccak in forum Tips & Tweaks
    Replies: 0
    Last Post: 11-02-2009, 11:46 AM
  5. How to Connect MySQL database from PHP
    By Booth in forum Software Development
    Replies: 3
    Last Post: 21-01-2009, 09:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,029,783.16157 seconds with 16 queries