PC Review


Reply
Thread Tools Rate Thread

bind variables oracle visual basic

 
 
cptkirkh
Guest
Posts: n/a
 
      27th Jul 2007
I have a query that looks up the highest value for column a and then
returns column a and column b. It uses a nested select in the from
clause. I want to use bind variables for my parameters but have found
out i can't use bind variables in the from clause. It keeps returning
no records when i can run this same query in toad and it returns
records. My question is can anyone help me wiht how to do this? Here
is my code:

Dim con As New OracleConnection(cnCICString)
Dim cmd As New OracleCommand
Dim da As OracleDataAdapter = New OracleDataAdapter(cmd)
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "select ec.ec_export_number,ec_date from
event_campaign ec, " & _
" (select max(ec_export_number) as maxexport from
event_campaign" & _
" where EC_PURPOSE = :event_purpose AND EC_ITEM_SENT
= :item_sent" & _
" and EC_SQL = :sql_totalcount ) maxresults where " & _
" ec.ec_export_number = maxresults.maxexport and EC_PURPOSE
= :event_purpose AND EC_ITEM_SENT = :item_sent " & _
" and EC_SQL = :sql_totalcount"

cmd.Parameters.Add(":sql_totalcount", OracleDbType.Varchar2).Value =
"select cli_rid from dual"
cmd.Parameters.Add(":event_purpose",
OracleDbType.Varchar2).Value = "20070511TXAM"
cmd.Parameters.Add(":item_sent", OracleDbType.Varchar2).Value
= "POSTCARD"

 
Reply With Quote
 
 
 
 
glennanthonyb
Guest
Posts: n/a
 
      31st Jul 2007
Colon's are only required in the SQL statement, remove them from the
parameter name argument passed to the Add method.

"cptkirkh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a query that looks up the highest value for column a and then
> returns column a and column b. It uses a nested select in the from
> clause. I want to use bind variables for my parameters but have found
> out i can't use bind variables in the from clause. It keeps returning
> no records when i can run this same query in toad and it returns
> records. My question is can anyone help me wiht how to do this? Here
> is my code:
>
> Dim con As New OracleConnection(cnCICString)
> Dim cmd As New OracleCommand
> Dim da As OracleDataAdapter = New OracleDataAdapter(cmd)
> con.Open()
> cmd.Connection = con
> cmd.CommandType = CommandType.Text
> cmd.CommandText = "select ec.ec_export_number,ec_date from
> event_campaign ec, " & _
> " (select max(ec_export_number) as maxexport from
> event_campaign" & _
> " where EC_PURPOSE = :event_purpose AND EC_ITEM_SENT
> = :item_sent" & _
> " and EC_SQL = :sql_totalcount ) maxresults where " & _
> " ec.ec_export_number = maxresults.maxexport and EC_PURPOSE
> = :event_purpose AND EC_ITEM_SENT = :item_sent " & _
> " and EC_SQL = :sql_totalcount"
>
> cmd.Parameters.Add(":sql_totalcount", OracleDbType.Varchar2).Value =
> "select cli_rid from dual"
> cmd.Parameters.Add(":event_purpose",
> OracleDbType.Varchar2).Value = "20070511TXAM"
> cmd.Parameters.Add(":item_sent", OracleDbType.Varchar2).Value
> = "POSTCARD"
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ADO and Oracle Bind-Variables steph Microsoft Excel Discussion 1 28th Oct 2009 04:07 PM
Using Bind Variables in pass-thru query to Oracle DB. chris Microsoft Access Queries 1 3rd Feb 2009 07:54 PM
Oracle bind variables causing runtime error Shawn Mason Microsoft Dot NET 0 29th Jun 2007 04:25 PM
Need some help with Visual Basic and Oracle Tom Rahav Microsoft Dot NET 1 18th Oct 2005 03:56 AM
Anybody know how to execute a sql or oracle script file from Visual Basic 6 povor Microsoft VB .NET 3 6th Jul 2005 08:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:50 AM.