Database connect and retrieve in c#
Solved/Closed
Related:
- Database connect and retrieve in c#
- Access database download - Download - Databases
- Borland database engine download - Download - Databases
- Turn off usb connect sound - Guide
- How to connect ps4 to pc - Guide
- How to connect mp3 player to computer - Guide
8 responses
epsiman
Posts
306
Registration date
Tuesday November 18, 2008
Status
Member
Last seen
February 2, 2010
162
May 20, 2009 at 03:54 AM
May 20, 2009 at 03:54 AM
the code is
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();
// Insert code to process data.
}
catch (Exception caught)
{
MessageBox.Show(caught.Message);
}
finally
{
conn.Close();
}
}
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();
// Insert code to process data.
}
catch (Exception caught)
{
MessageBox.Show(caught.Message);
}
finally
{
conn.Close();
}
}
Notice this line
-> database. conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data source= @"path \AccessFile.mdb";
Should be
database. conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=AccessFile.mdb";
Other Connection String Sample.
Visual Basic]
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#]
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++]
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();
}
-> database. conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data source= @"path \AccessFile.mdb";
Should be
database. conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=AccessFile.mdb";
Other Connection String Sample.
Visual Basic]
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#]
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++]
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();
}
using System.Data.Oledb;
namespace consample
{
pubic class OledbConnection
{
public void Perform()
{
OledbConnection con= new OledbCOnnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb")//Data provider for MS ACCESS
con.Open();
OLEDBCommand cmd=new OLEDBCOmman();
cmd.Connection=con;
cmd.CommandType=CommandType.Text;
cmd.CommandText="Select * from emp";
OledbDataReader dr= new OledbDataReader();
dr=cmd.Executereader();
while (dr.Read()==true)
{
/// Do some coding here
}
}
}
}
namespace consample
{
pubic class OledbConnection
{
public void Perform()
{
OledbConnection con= new OledbCOnnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb")//Data provider for MS ACCESS
con.Open();
OLEDBCommand cmd=new OLEDBCOmman();
cmd.Connection=con;
cmd.CommandType=CommandType.Text;
cmd.CommandText="Select * from emp";
OledbDataReader dr= new OledbDataReader();
dr=cmd.Executereader();
while (dr.Read()==true)
{
/// Do some coding here
}
}
}
}
string str = "server=.;database=master;uid=sa;password=;";
SqlConnection con = new SqlConnection(str);
con.Open();
This is only for connecting database
SqlConnection con = new SqlConnection(str);
con.Open();
This is only for connecting database
How To Create Connection BetWeen C#.net 2005 (Window Application) And MS Access 2003
With Some Example
Hope!
Thank-You!!!!!!
With Some Example
Hope!
Thank-You!!!!!!
Didn't find the answer you are looking for?
Ask a question
using System.Data.Oledb;
namespace cons
{
pubic class OledbConnection
{
public void do()
{
OledbConnection con= new OledbCOnnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\database.mdb")//Data provider for MS ACCESS
con.Open();
OLEDBCommand cmd=new OLEDBCOmman();
cmd.Connection=con;
cmd.CommandType=CommandType.Text;
cmd.CommandText="Select * from emp";
OledbDataReader dr= new OledbDataReader();
dr=cmd.Executereader();
while (dr.Read())
{
/// Do some coding here
}
namespace cons
{
pubic class OledbConnection
{
public void do()
{
OledbConnection con= new OledbCOnnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\database.mdb")//Data provider for MS ACCESS
con.Open();
OLEDBCommand cmd=new OLEDBCOmman();
cmd.Connection=con;
cmd.CommandType=CommandType.Text;
cmd.CommandText="Select * from emp";
OledbDataReader dr= new OledbDataReader();
dr=cmd.Executereader();
while (dr.Read())
{
/// Do some coding here
}
1. First of all you have to import required namespace , in case is for sqlserver is sqlclient by using directive.
using System.Data.SqlClient;
2. Create object of sqlconnection class
private SqlConnection _Connection = New SqlConnection();
3. then Assign the path to sqlserver server by setiing ConnectionString property to the sqlserver path.
_connention.ConnectionString = " Data Source=.\\Servername;
Initial Catalog=DatabaseName; Integrated Security=True";
4. then Open connection by calling Open() method
_connection.Open();
Here we go
using System.Data.SqlClient;
2. Create object of sqlconnection class
private SqlConnection _Connection = New SqlConnection();
3. then Assign the path to sqlserver server by setiing ConnectionString property to the sqlserver path.
_connention.ConnectionString = " Data Source=.\\Servername;
Initial Catalog=DatabaseName; Integrated Security=True";
4. then Open connection by calling Open() method
_connection.Open();
Here we go
i have tried
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=Db.mdb");
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand("SELECT * from temp", conn);
but it gives an error on conn, as if the object has not been created...plzzz can anyone help me..thanx in advance
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=Db.mdb");
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand("SELECT * from temp", conn);
but it gives an error on conn, as if the object has not been created...plzzz can anyone help me..thanx in advance
Jul 13, 2009 at 03:22 PM
Aug 30, 2009 at 12:39 AM
May 14, 2010 at 06:16 AM