Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing paramter value to sql statement 1

Status
Not open for further replies.

josie2007

Technical User
Apr 14, 2007
90
US
I am passing the paramter value to my sql statement and below is the code I used to pass the value to sql statement. p.contid is a character field.Oracle is the db. thanks

...
.Append(" AND P.contid = :ContractNumber ")
...


Dim cmdItemDetail As OracleCommand = New OracleCommand()
cmdItemDetail.Parameters.AddWithValue(":ContractNumber", "'"& ContractId & "'")
 
Sorry guys,
For some reason the value is not passing to the sql statement.It just return nothing but when I hard coded the value like this Append(" AND P.contid = '070002' then I get the right outcome and I am just wondering where I made a mistake. thanks
 
try placing the quotes to the sql string instead of incorporating them as part of the parameter value.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I create this code snippet and it seems to work. I am using the Oracle Data Provider for .Net, not the OracleClient. But it should work similarly.

Code:
string cmd = "SELECT * FROM hr.Employees WHERE Employee_ID = :EmployeeID";

//open connection
objConn.Open();
//build command object
OracleCommand objCmd = new OracleCommand(cmd,objConn);
objCmd.CommandType = CommandType.Text;
objCmd.Parameters.Add(":EmployeeID",txtEmpID.Text);

OracleDataReader objRdr = objCmd.ExecuteReader();

while(objRdr.Read())
{
   Response.Write(objRdr.GetValue(1).ToString();
}
}
 
Folks, thanks for the reply. I did like what Jason suggested but that did not solve the problem. when I hard coded like this P.contid ='070002' it works fine. It looks a bit stranget to me. any help is appreciated.

.Append(" AND P.contid = ""'"" & :ContractNumber & ""'"" ")
 
try this instead. you may need to supply the data type.
Code:
cmdItemDetail.Parameters.Add("ContractNumber", OracleDbType.[my type here]).Value = ContractId;

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top