SSISO Community

시소당

C#과 Oracle 오라클 연동

========오라클  접속===============================================

string  strConn  =  "Data  Source=서버이름;User  ID=id;Password=pass";
string  strQuery  =  "select  *  from  테이블명";

OracleConnection  oraconn  =  null;
OracleCommand  oracomm  =  null;
OracleDataAdapter  oraadp  =  null;

DataSet  ds  =  new  DataSet();  //  DataSet("test");로  해도  되고  안해도  되고
try
{
        oraconn  =  new  OracleConnection(strConn);

        oracomm  =  new  OracleCommand(strQuery,oraconn);  //  아래  두줄과  같은  내용
        //oracomm  =  oraconn.CreateCommand();
        //oracomm.CommandText  =  strQuery;

        oraadp  =  new  ORacleDataAdapter(oracomm);
        oraconn.Open();

        oraadp.Fill(ds,"테이블명");

        dataGrid1.DataSource  =  ds.Tables["테이블명"];  //  아래  두줄과  같은  내용
        //dataGrid1.DataSource  =  ds.Tables["ex"].Rows[0]["NAME"];
        //dataGrid1.DataSource  =  ds.Tables[0].DefaultView;

}
catch(Exception  ex)
{
        MessageBox.Show(ex.Message,"경고");
}
finally
{
        if  (dataadapter  !=  null)
        {
                dataadapter.Dispose();
        }

        if  (command  !=  null)
        {
                command.Dispose();
        }

        if  (connection  !=  null)
        {
                if  (connection.State  ==  System.Data.ConnectionState.Open)
                {
                        connection.Close();
                }
        connection.Dispose();
        }
}
[2008년  04월  04일  11:42:34  수정되었습니다.]

6957 view

4.0 stars