all groups > c# > june 2004 >
You're in the

c#

group:

Oracle connectivity in C#


Oracle connectivity in C# ibrahim NO[at]SPAM islamabad-dot-net.no-spam.invalid
6/24/2004 10:54:39 PM
c#:
can anyone send a code for the oracle connectivity wid C#.. would be
really tahnkful ..
Desert Desperado 8)


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
Re: Oracle connectivity in C# Stefano \
6/25/2004 10:22:53 AM
Re: Oracle connectivity in C# Ashutosh Ambekar
6/25/2004 3:37:06 PM
The following code explains how to connect to oracle db and display =
fetched data into a datagrid :o)

1. Create a winforms project and add a datagrid control on it and call =
it as datagrid1
2. Add a button control on the form and call it button1.
3. Add a reference to System.Data.OracleClient.dll

Then add following lines near the using statements
using System.Data;
using System.Data.OracleClient;
Here is the code for fetchind data from oracle table and displaying it =
in the datagrid when user clicks on the button.

private void button1_Click(object sender, System.EventArgs e)
{=20
try
{
System.Data.OracleClient.OracleConnection objConn =3D=20
new System.Data.OracleClient.OracleConnection("Data Source=3D<your =
db service name>;User ID=3D'<user name>'; password=3D'<password>'" );
//note that user id and password values are specified in single =
quotes
objConn.Open();

String strCommand;
strCommand =3D"Select * from <table name>";=20
//Create new command object

System.Data.OracleClient.OracleCommand objCommand =3D new =
System.Data.OracleClient.OracleCommand(strCommand,objConn);=20

DataSet ds=3Dnew DataSet() ;=20
System.Data.OracleClient.OracleDataAdapter objDa =3D new =
System.Data.OracleClient.OracleDataAdapter (objCommand);=20

objDa.Fill(ds);
dataGrid1.DataSource =3D ds;=20
}
catch(System.Exception ex)=20
{
MessageBox.Show (ex.Message);=20
}
}

HTH,
Ashutosh

[quoted text, click to view]
AddThis Social Bookmark Button