Simple CRUD .net i’ve make easier to use

Nota untuk rujukan bila diperlukan;

====SELECT===========

Conn.Open();

string sql =
@”SELECT * FROM DB”;

OracleCommand cmd = new OracleCommand();
cmd.CommandText = sql;
cmd.Parameters.Add(“PARAMETER”, PASS PARAMETER);
cmd.Connection = Conn;

OracleDataReader dr = null;
dr = cmd.ExecuteReader();

if (dr.HasRows)
{

while (dr.Read())
{
lblA.Text = dr[“”].Tostring();
}
}

Conn.Close();

========= INSERT ============

try
{
Conn.Open();

string sqlinsert = @”INSERT INTO tb A
(field a,field  b, field  c, field d, field  e)
VALUES
(:fieldA, :fieldB , :fieldC, :fieldD, :fieldE, SYSDATE, )”;

OracleCommand cmd = new OracleCommand(sqlinsert, Conn);

cmd.Parameters.Add(new OracleParameter(“fieldA”, valueA));
cmd.Parameters.Add(new OracleParameter(“fieldB “, valueB));
cmd.Parameters.Add(new OracleParameter(“fieldC”, valueC));
cmd.Parameters.Add(new OracleParameter(“fieldD”, valueD));
cmd.Parameters.Add(new OracleParameter(“fieldE”, valueE));
cmd.ExecuteOracleScalar();

======== UPDATE =============

Conn.Open();

string sql = “UPDATE tb A ” +
“SET field a= :field A, ” +
“field b = :field B” +
“WHERE field c = :field C ” +
“AND DATE_DELETE IS NULL “;

OracleCommand cmd = new OracleCommand(sql, Conn);
cmd.Parameters.Add(new OracleParameter(“field A”, valueA));
cmd.Parameters.Add(new OracleParameter(“field B”, valueB));
cmd.Parameters.Add(new OracleParameter(“field C”, valueC));
cmd.ExecuteOracleScalar();
Conn.Close();