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;
}
EDIT: I added @ to the parameter field name, but it still does not fix it.
You need to use something like this:
More can be found in this MSDN article: http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oraclecommand.parameters%28v=vs.100%29.aspx
It is advised you use the : character instead of @ for Oracle.
Remove single quotes around @username, and with respect to oracle use
:
with parameter name instead of@
, like:Source: Using Parameters
You need to have the "@" symbol:
Oracle has a different syntax for parameters than Sql-Server. So use : instead of @
When using named parameters in an OracleCommand you must precede the parameter name with a colon (:).
http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oraclecommand.parameters.aspx
// PT: Eu tive este mesmo problema ao utilizar o Namespace Oracle.DataAccess.Client;
// ES: Tenía este mismo problema cuando se utiliza el Namespace Oracle.DataAccess.Client;
// EN: I had this same problem using the Oracle.DataAccess.Client Namespace;
// PT: Eu resolvi desta forma:
// ES: He resuelto de esta manera:
// EN: I solved it this way
using Oracle.DataAccess.Client;