I'm attempting to write a prepared statement for retrieving data using a SqlDataSource, but cannot seem to compose a good SelectCommand statement (7th line below) to do this. Could someone please shed some light on how to do this?
OracleCommand cm = new OracleCommand();
cm.CommandText = "SELECT FTPOSCODE FROM PPTBL WHERE DESC LIKE '%" + "@parm1" + "%";
cm.Parameters.Add("@parm1", "ACCOUNT");
OracleConnection cn = new OracleConnection();
cn.ConnectionString = ConfigurationManager.ConnectionStrings["ORCLConnectionString"].ConnectionString;
cn.Open();
SqlDataSource1.SelectCommand = cm.ToString(); // "ORA-00900: invalid SQL statement"
cn.Close();
The above was simplified. Slawomir and I continued in chat and came up with the following working code. Thanks Slawomir!
using (OracleConnection cn = new OracleConnection(ConfigurationManager.ConnectionStrings["ORCLConnectionString"].ConnectionString)) {
SqlDataSource1.SelectCommand = "SELECT FTPOSCODE, PTPOSCODE, POSCLASSTITLE, FKSA, JOBCAT, PAYGRADE, HRPAYRANGE, MONTHPAYRANGE FROM HR_PAY_PLAN WHERE UPPER(POSDESC) LIKE :1 OR UPPER(POSCLASSTITLE) LIKE :2 ORDER BY POSCLASSTITLE";
SqlDataSource1.SelectParameters.Add(":1", "%" + key1 + "%");
SqlDataSource1.SelectParameters.Add(":2", "%" + key1 + "%");
}