private OleDbDataReader rd;
private OleDbConnection Conn;
private string strRet;
private OleDbCommand cmd;
private StringBuilder sbSQL;
private OleDbParameter paramnSeq;
try
{
// SQLOLEDB MSDAORA
Conn = new OleDbConnection("Provider=MSDAORA;Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.xxx )(PORT = 1521)))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = GROUP))); User Id =; Password =;");
Conn.Open();
try
{
sbSQL = new StringBuilder();
sbSQL.Append(" SELECT * ");
sbSQL.Append(" FROM HEIS_CUSTOMER ");
sbSQL.Append(" WHERE 1=1 ");
sbSQL.Append(" AND CUSTOMER_CODE = ? ");
paramnSeq = new OleDbParameter("CUSTOMER_CODE", OleDbType.Char, 4);
paramnSeq.Value = "0003";
cmd = new OleDbCommand(sbSQL.ToString(), Conn);
cmd.Parameters.Add(paramnSeq);
rd = cmd.ExecuteReader();
if (rd.Read())
{
strRet = rd["CUSTOMER_CODE"].ToString();
}
else
{
strRet = "";
}
}
catch (System.Exception e1)
{
throw e1;
}
finally
{
rd.Close();
}
}
catch (System.Exception e2)
{
throw e2;
}
finally
{
Conn.Close();
}
'lang) C#'에 해당되는 글 3건
- 2009/10/09 OLE DB로 oracle이건 MSSQL이건 데이터를 가져오기 위한 기초 코드
- 2009/10/06 ORACLE Connect Sample using DataAdapter without TNS
- 2009/10/05 JET OLEDB Connect Sample using DataAdapter
#region Using directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Windows.Forms;
#endregion
namespace UsingADOManagedProvider
{
partial class ADONetForm1 : Form
{
public ADONetForm1( )
{
InitializeComponent( );
// connect to Northwind Access database
string connectionString = "Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.XXX )(PORT = 1521)))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = GROUP))); User Id =; Password =";
// get records from the customers table
string commandString = "Select CompanyName, ContactName from Customers";
// create the data set command object
// and the DataSet
OleDbDataAdapter DataAdapter = new OleDbDataAdapter( commandString, connectionString );
DataSet DataSet = new DataSet( );
// fill the data set object
DataAdapter.Fill( DataSet, "Customers" );
// Get the one table from the DataSet
DataTable dataTable = DataSet.Tables[0];
// for each row in the table, display the info
foreach ( DataRow dataRow in dataTable.Rows )
{
lbCustomers.Items.Add( dataRow["CompanyName"] + " (" + dataRow["ContactName"] + ")" );
}
}
}
}
#region Using directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Windows.Forms;
#endregion
namespace UsingADOManagedProvider
{
partial class ADONetForm1 : Form
{
public ADONetForm1( )
{
InitializeComponent( );
// connect to Northwind Access database
string connectionString = "provider=Microsoft.JET.OLEDB.4.0; " + "data source = c:\\nwind.mdb";
// get records from the customers table
string commandString = "Select CompanyName, ContactName from Customers";
// create the data set command object
// and the DataSet
OleDbDataAdapter DataAdapter = new OleDbDataAdapter( commandString, connectionString );
DataSet DataSet = new DataSet( );
// fill the data set object
DataAdapter.Fill( DataSet, "Customers" );
// Get the one table from the DataSet
DataTable dataTable = DataSet.Tables[0];
// for each row in the table, display the info
foreach ( DataRow dataRow in dataTable.Rows )
{
lbCustomers.Items.Add( dataRow["CompanyName"] + " (" + dataRow "ContactName"] + ")" );
}
}
}
}




댓글을 달아 주세요