努力在 C# 中使用绑定变量
Struggling to use bind variable in C#
我正在尝试在 C# 中使用绑定变量来获取 select 查询中的记录。下面的代码是我尝试过的,但出现异常:ORA-01006: bind variable does not exist。我不知道变量在哪里不存在或其他什么?
string sleeveListQuery = @"select col from table where id = :V1 :V2 ";
inClause="some condition";
List<SleeveSearch> sleeveSearchList= new List<SleeveSearch>();
using (OracleConnection objConn = new OracleConnection(ConnectionString))
{
objConn.Open();
using (var command = objConn.CreateCommand())
{
command.CommandText = sleeveListQuery;
command.Parameters.Add(":V1", OracleDbType.Int32, Int32.Parse(univId), ParameterDirection.Input);
command.Parameters.Add(":V2", OracleDbType.Varchar2, inClause, ParameterDirection.Input);
OracleDataReader dr = command.ExecuteReader();
while (dr.Read())
{
SleeveSearch dataRow = new SleeveSearch();
dataRow.SleeveName = dr["SLEEVENAME"].ToString();
sleeveSearchList.Add(dataRow);
}
}
}
您正在向命令添加参数,但没有为它们提供任何值。即:
//...
command.Parameters[":V1"].Value = 10;
command.Parameters[":V2"].Value = "Hello";
//...
PS:可能你的意思是:
... where id = :V1 and something = :V2
我正在尝试在 C# 中使用绑定变量来获取 select 查询中的记录。下面的代码是我尝试过的,但出现异常:ORA-01006: bind variable does not exist。我不知道变量在哪里不存在或其他什么?
string sleeveListQuery = @"select col from table where id = :V1 :V2 ";
inClause="some condition";
List<SleeveSearch> sleeveSearchList= new List<SleeveSearch>();
using (OracleConnection objConn = new OracleConnection(ConnectionString))
{
objConn.Open();
using (var command = objConn.CreateCommand())
{
command.CommandText = sleeveListQuery;
command.Parameters.Add(":V1", OracleDbType.Int32, Int32.Parse(univId), ParameterDirection.Input);
command.Parameters.Add(":V2", OracleDbType.Varchar2, inClause, ParameterDirection.Input);
OracleDataReader dr = command.ExecuteReader();
while (dr.Read())
{
SleeveSearch dataRow = new SleeveSearch();
dataRow.SleeveName = dr["SLEEVENAME"].ToString();
sleeveSearchList.Add(dataRow);
}
}
}
您正在向命令添加参数,但没有为它们提供任何值。即:
//...
command.Parameters[":V1"].Value = 10;
command.Parameters[":V2"].Value = "Hello";
//...
PS:可能你的意思是:
... where id = :V1 and something = :V2