Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , ,

Sponsored Links



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

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 19-11-2009
Member
 
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.
Reply With Quote
  #2  
Old 19-11-2009
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
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();
}
}
Reply With Quote
  #3  
Old 19-11-2009
Member
 
Join Date: May 2008
Posts: 1,990
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.
Reply With Quote
  #4  
Old 19-11-2009
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
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();
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Connect Database and Retrieve it with the use of C#?"
Thread Thread Starter Forum Replies Last Post
How to connect PHP to mySQL Database Nathen Tips & Tweaks 2 17-07-2011 04:49 AM
Using Ajax to Retrieve Data from a MySQL Database warthogweb Software Development 1 19-11-2010 10:46 PM
How to connect ASP to different database Elijah2010 Software Development 5 16-02-2010 12:01 AM
how to connect VB6 to database WILTON Software Development 3 08-12-2009 04:26 AM
Connect to Oracle database using VB 6.0 Ariadne Software Development 2 19-01-2009 06:09 PM


All times are GMT +5.5. The time now is 11:58 AM.