2016년 4월 27일 수요일

C# Oracle bind변수사용 , C# preparedstatement 실행 예제

string oradb = Settings.Default.ConnectionString;

OracleConnection conn = new OracleConnection(oradb);
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;


/******************************************************************************/
/* SELECT 구문 PREPAREDSTATEMENT 예제  */
cmd.CommandText = @"select * from table_name where item_Code = :val";
cmd.Parameters.Add("val", "06");
OracleDataReader od = cmd.ExecuteReader();
while (od.Read())
{
  string s_ = od["col_name01"].ToString();
  string s_1 = od["col_name02"].ToString();
}
/**************************************************************************/
cmd.Parameters.Clear();
/******************************************************************************/
/* INSERT 구문 PREPAREDSTATEMENT 예제  */
cmd.CommandText = @"insert into table_name (A , N, S) values (:val1, :val2, :val3)";
cmd.Parameters.Add("val1", "02");
cmd.Parameters.Add("val2", "2");
cmd.Parameters.Add("val3", DateTime.Now);
cmd.Prepare();       /* <-- nonquery="" p="" prepare="">cmd.ExecuteNonQuery();
/******************************************************************************/

conn.Close();
conn.Dispose();

댓글 없음:

댓글 쓰기