数据库
首页 > 数据库> > C#使用OracleParameter操作数据库

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中使用:占位。

标签:username,p2,C#,数据库,OracleParameter,new,password,conn
来源: https://www.cnblogs.com/monkey6/p/12222621.html