C#使用OracleParameter操作数据库

 public static int GetScalar(string sql,params OracleParameter [] OracleParms)
        {

            using (OracleConnection conn = new OracleConnection(conStr))
            {
                if (conn.State == System.Data.ConnectionState.Closed)
                {
                    conn.Open();
                }

                OracleCommand cmd = new OracleCommand(sql, conn);
                cmd.Parameters.AddRange(OracleParms);
                return Convert.ToInt32(cmd.ExecuteScalar());
            }
        }


 OracleParameter p1 = new OracleParameter(":username", OracleDbType.Varchar2);
 p1.Value = username;
 OracleParameter p2 = new OracleParameter(":password", OracleDbType.Varchar2);
 p2.Value = password;
 if (OracleHelper.GetScalar("select count(*) from user_info where name=:username and password=:password", p1, p2) == 1)
 {
    MessageBox.Show("登錄成功");
 }

SqlServer中使用@来进行占位,oracle中使用:占位。

上一篇:数据库系统设计综合实验


下一篇:C++指针做形参与指针的引用做形参的区别