我正在尝试编写用于使用 SqlDataSource 检索数据的准备好的语句,但似乎无法编写一个好的 SelectCommand 语句(下面的第 7 行)来执行此操作。有人可以说明如何做到这一点吗?
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();
以上是简化的。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 + "%");
}