SQL的OracleCommand绑定的参数 [英] OracleCommand SQL Parameters Binding
本文介绍了SQL的OracleCommand绑定的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我与以下参数的结合的问题。该连接工作,因为我已经没有使用的参数进行了测试。但是,仍然使用@用户名,而不是如jsmith的正在执行的查询的前值。
I have a problem with the binding of the below parameter. The connection works because I had tested it without using parameters. However, the value of the query before being executed is still using '@userName' instead of 'jsmith' for example.
这是什么问题?这难道不是绕过去结合的正确方法?
What is the problem? Is this not the right way to go around binding?
public static String GetFullName(String domainUser)
{
DataTable dT;
String fullName = "";
OracleConnection db = DatabaseAdapter.GetConn();
db.Open();
OracleCommand oraCommand = new OracleCommand("SELECT fullname FROM user_profile WHERE domain_user_name = '@userName'", db);
oraCommand.BindByName = true;
oraCommand.Parameters.Add(new OracleParameter("@userName", domainUser));
OracleDataReader oraReader = null;
oraReader = oraCommand.ExecuteReader();
if (oraReader.HasRows)
{
while (oraReader.Read())
{
fullName = oraReader.GetString(0);
}
}
else
{
return "No Rows Found";
}
oraReader.Close();
db.Close();
db.Dispose();
return fullName;
}
编辑:我添加@到参数字段名称,但它仍然没有解决。
I added @ to the parameter field name, but it still does not fix it.
推荐答案
的各地@username删除单引号,的且相对于使用Oracle的:
与参数名称,而不是 @
,如:
Remove single quotes around @username, and with respect to oracle use :
with parameter name instead of @
, like:
OracleCommand oraCommand = new OracleCommand("SELECT fullname FROM sup_sys.user_profile
WHERE domain_user_name = :userName", db);
oraCommand.Parameters.Add(new OracleParameter("userName", domainUser));
来源:使用参数
这篇关于SQL的OracleCommand绑定的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文