Database connect and retrieve in c#

Solved/Closed
raja - May 20, 2009 at 02:39 AM
 decent10_cs - Jun 14, 2010 at 01:23 AM
Hello,
I am ilayaraja doing my project work,i have one problem
my project doing in asp.net
but I don't know how to connect the database in asp.net using c# and how to retrieve in database to web application .
please give the answer my question, urgently.
Related:

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
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();
}
}
109
missing a double quote somewhere
0
Are you sure is this correct? I'll try to do this my self and send a reply to if positive.
0
database. conn.ConnectionString = @'Provider=Microsoft.Jet.OLEDB.4.0; Data source= @'path \AccessFile.mdb";
0
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();
}
46
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
}
}
}
}
0
string str = "server=.;database=master;uid=sa;password=;";
SqlConnection con = new SqlConnection(str);
con.Open();

This is only for connecting database
18
How To Create Connection BetWeen C#.net 2005 (Window Application) And MS Access 2003
With Some Example

Hope!

Thank-You!!!!!!
12

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
}
10
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
8
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
3
code to connection of database
0