我正在尝试在Oracle DB 11g上执行简单的select .... where
语句。
当用户点击“编辑”按钮时,它会将记录字段从gridview发送回DAL。我想从DB检索现有记录以与gridview中编辑的记录进行比较,以查看用户所做的编辑。我使用此代码不断收到上述错误。我已经验证问题出在WHERE语句中,ProductCode
有一个执行值,所以不确定为什么它会发疯。
public virtual void EditProduct(ProductRecord productRecord)
{
OracleConnection conn = new OracleConnection(_connectionString);
OracleTransaction transaction = null;
if (conn != null)
{
try
{
conn.Open();
transaction = conn.BeginTransaction();
string sql = "SELECT DIRECTION, PRODUCTCODE, PRODUCTDESC, ISACTIVE
from PRODUCT PRD where PRD.PRODUCTCODE = :PRM_ProductCode";
OracleCommand command = new OracleCommand(sql, conn);
OracleParameter param = new OracleParameter("PRM_ProductCode",OracleDbType.Varchar2);
param.Value = productRecord.ProductCode;
command.Parameters.Add(param);
param = new OracleParameter("PRM_ProductCode", OracleDbType.Varchar2);
param.Value = productRecord.ProductCode;
command.Parameters.Add(param);
param = new OracleParameter("PRM_DIRECTION", OracleDbType.Varchar2);
param.Value = productRecord.Direction;
command.Parameters.Add(param);
param = new OracleParameter("PRM_IsActive", OracleDbType.Varchar2);
param.Value = productRecord.Active;
command.Parameters.Add(param);
param = new OracleParameter("PRM_ProductDesc", OracleDbType.Varchar2);
param.Value = productRecord.ProductDesc;
command.Parameters.Add(param);
OracleDataReader rs = command.ExecuteReader();
while (rs.Read())
{
..code
}
rs.Close();
command.Dispose();
//Update existing product record with new product record
sql = "UPDATE PRODUCT SET DIRECTION = :PRM_DIRECTION, ISACTIVE = :PRM_IsActive, PRODUCTDESC = :PRM_ProductDesc WHERE PRODUCTCODE = :PRM_ProductCode";
command = new OracleCommand(sql, conn);
command.ExecuteNonQuery();
command.Dispose();
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
}
finally
{
if (conn != null)
conn.Close();
}
}
}
注意 ProductCode
不是主键。不幸的是,当从gridview传递记录时,当前没有评估PK。但是,ProductCode
是一个独特的字段。任何帮助将不胜感激。
productRecord
正在从表示层传入。
答案 0 :(得分:0)
你想执行一个查询,你无法用ExecuteNonQuery
执行(这个名字有点赠品......)
请ExecuteReader
解释// Execute command, create OracleDataReader object
OracleDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
// process your result(s)
}
:
var html = document.documentElement.innerHTML;
var n = html.search("runn1ng");