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