PC Review


Reply
Thread Tools Rate Thread

bind variables and sql

 
 
cptkirkh
Guest
Posts: n/a
 
      7th Aug 2007
I a trying to store certain sql queries in a table to reference
later. I want to perform a sql query to see if they are in the table
and i want to use bind variables. HOw can i do this?

Here is a sample of my code:
Dim sqltorun As String = "select max(ec_export_number) from
event_campaign " & _
" where EC_PURPOSE
= :event_purpose AND EC_ITEM_SENT = :item_sent" & _
" AND EC_SQL = :sql_totalcount "




Dim cmd As New OracleCommand(sqltorun, myConnection)



Try
cmd.Connection.Open()
Catch ex As Exception
MsgBox("Please close the program and reopen to establish a
new connection and if it happens again call MIS" + export_date,
MsgBoxStyle.OkOnly, title)
End Try

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"

Try 'go and get the export number if false no query has been run
before


export_num = cmd.ExecuteScalar

When i get to this step i get illegal number or vairable as the
exception.
This sql code works just fine when i run it in sql plus or toad.
Thanks for your help.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2VycnkgTW9vcm1hbg==?=
Guest
Posts: n/a
 
      7th Aug 2007
cptkirkh,

Try naming your parameters without the colon. For example:

cmd.Parameters.Add("sql_totalcount", ...

Kerry Moorman

"cptkirkh" wrote:

> I a trying to store certain sql queries in a table to reference
> later. I want to perform a sql query to see if they are in the table
> and i want to use bind variables. HOw can i do this?
>
> Here is a sample of my code:
> Dim sqltorun As String = "select max(ec_export_number) from
> event_campaign " & _
> " where EC_PURPOSE
> = :event_purpose AND EC_ITEM_SENT = :item_sent" & _
> " AND EC_SQL = :sql_totalcount "
>
>
>
>
> Dim cmd As New OracleCommand(sqltorun, myConnection)
>
>
>
> Try
> cmd.Connection.Open()
> Catch ex As Exception
> MsgBox("Please close the program and reopen to establish a
> new connection and if it happens again call MIS" + export_date,
> MsgBoxStyle.OkOnly, title)
> End Try
>
> 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"
>
> Try 'go and get the export number if false no query has been run
> before
>
>
> export_num = cmd.ExecuteScalar
>
> When i get to this step i get illegal number or vairable as the
> exception.
> This sql code works just fine when i run it in sql plus or toad.
> Thanks for your help.
>
>

 
Reply With Quote
 
cptkirkh
Guest
Posts: n/a
 
      8th Aug 2007
On Aug 7, 5:12 pm, Kerry Moorman
<KerryMoor...@discussions.microsoft.com> wrote:
> cptkirkh,
>
> Try naming your parameters without the colon. For example:
>
> cmd.Parameters.Add("sql_totalcount", ...
>
> Kerry Moorman
>
>
>
> "cptkirkh" wrote:
> > I a trying to store certain sql queries in a table to reference
> > later. I want to perform a sql query to see if they are in the table
> > and i want to use bind variables. HOw can i do this?

>
> > Here is a sample of my code:
> > Dim sqltorun As String = "select max(ec_export_number) from
> > event_campaign " & _
> > " where EC_PURPOSE
> > = :event_purpose AND EC_ITEM_SENT = :item_sent" & _
> > " AND EC_SQL = :sql_totalcount "

>
> > Dim cmd As New OracleCommand(sqltorun, myConnection)

>
> > Try
> > cmd.Connection.Open()
> > Catch ex As Exception
> > MsgBox("Please close the program and reopen to establish a
> > new connection and if it happens again call MIS" + export_date,
> > MsgBoxStyle.OkOnly, title)
> > End Try

>
> > 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"

>
> > Try 'go and get the export number if false no query has been run
> > before

>
> > export_num = cmd.ExecuteScalar

>
> > When i get to this step i get illegal number or vairable as the
> > exception.
> > This sql code works just fine when i run it in sql plus or toad.
> > Thanks for your help.- Hide quoted text -

>
> - Show quoted text -


Kerry,
When i do that i now get "conversion from type DBnull to string
is not valid" This tells me that the query is returning nothing. If
I change my code to look like this it returns the value I am looking
for:

Dim sqltorun As String = "select max(ec_export_number) from
event_campaign " & _
" where EC_PURPOSE
= :event_purpose AND EC_ITEM_SENT = :item_sent" & _
" AND EC_SQL = 'select cli_rid from dual' "




Dim cmd As New OracleCommand(sqltorun, myConnection)



Try
cmd.Connection.Open()
Catch ex As Exception
MsgBox("Please close the program and reopen to establish a
new connection and if it happens again call MIS" + export_date,
MsgBoxStyle.OkOnly, title)
End Try





'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"


Try 'go and get the export number if false no query has been
run before




export_num = cmd.ExecuteScalar

 
Reply With Quote
 
=?Utf-8?B?S2VycnkgTW9vcm1hbg==?=
Guest
Posts: n/a
 
      8th Aug 2007
cptkirkh,

Shouldn't the select subquery be in parentheses, not single quotes?

Kerry Moorman

"cptkirkh" wrote:

> On Aug 7, 5:12 pm, Kerry Moorman
> <KerryMoor...@discussions.microsoft.com> wrote:
> > cptkirkh,
> >
> > Try naming your parameters without the colon. For example:
> >
> > cmd.Parameters.Add("sql_totalcount", ...
> >
> > Kerry Moorman
> >
> >
> >
> > "cptkirkh" wrote:
> > > I a trying to store certain sql queries in a table to reference
> > > later. I want to perform a sql query to see if they are in the table
> > > and i want to use bind variables. HOw can i do this?

> >
> > > Here is a sample of my code:
> > > Dim sqltorun As String = "select max(ec_export_number) from
> > > event_campaign " & _
> > > " where EC_PURPOSE
> > > = :event_purpose AND EC_ITEM_SENT = :item_sent" & _
> > > " AND EC_SQL = :sql_totalcount "

> >
> > > Dim cmd As New OracleCommand(sqltorun, myConnection)

> >
> > > Try
> > > cmd.Connection.Open()
> > > Catch ex As Exception
> > > MsgBox("Please close the program and reopen to establish a
> > > new connection and if it happens again call MIS" + export_date,
> > > MsgBoxStyle.OkOnly, title)
> > > End Try

> >
> > > 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"

> >
> > > Try 'go and get the export number if false no query has been run
> > > before

> >
> > > export_num = cmd.ExecuteScalar

> >
> > > When i get to this step i get illegal number or vairable as the
> > > exception.
> > > This sql code works just fine when i run it in sql plus or toad.
> > > Thanks for your help.- Hide quoted text -

> >
> > - Show quoted text -

>
> Kerry,
> When i do that i now get "conversion from type DBnull to string
> is not valid" This tells me that the query is returning nothing. If
> I change my code to look like this it returns the value I am looking
> for:
>
> Dim sqltorun As String = "select max(ec_export_number) from
> event_campaign " & _
> " where EC_PURPOSE
> = :event_purpose AND EC_ITEM_SENT = :item_sent" & _
> " AND EC_SQL = 'select cli_rid from dual' "
>
>
>
>
> Dim cmd As New OracleCommand(sqltorun, myConnection)
>
>
>
> Try
> cmd.Connection.Open()
> Catch ex As Exception
> MsgBox("Please close the program and reopen to establish a
> new connection and if it happens again call MIS" + export_date,
> MsgBoxStyle.OkOnly, title)
> End Try
>
>
>
>
>
> '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"
>
>
> Try 'go and get the export number if false no query has been
> run before
>
>
>
>
> export_num = cmd.ExecuteScalar
>
>

 
Reply With Quote
 
cptkirkh
Guest
Posts: n/a
 
      8th Aug 2007
On Aug 8, 8:42 am, Kerry Moorman
<KerryMoor...@discussions.microsoft.com> wrote:
> cptkirkh,
>
> Shouldn't the select subquery be in parentheses, not single quotes?
>
> Kerry Moorman
>
>
>
> "cptkirkh" wrote:
> > On Aug 7, 5:12 pm, Kerry Moorman
> > <KerryMoor...@discussions.microsoft.com> wrote:
> > > cptkirkh,

>
> > > Try naming your parameters without the colon. For example:

>
> > > cmd.Parameters.Add("sql_totalcount", ...

>
> > > Kerry Moorman

>
> > > "cptkirkh" wrote:
> > > > I a trying to store certain sql queries in a table to reference
> > > > later. I want to perform a sql query to see if they are in the table
> > > > and i want to use bind variables. HOw can i do this?

>
> > > > Here is a sample of my code:
> > > > Dim sqltorun As String = "select max(ec_export_number) from
> > > > event_campaign " & _
> > > > " where EC_PURPOSE
> > > > = :event_purpose AND EC_ITEM_SENT = :item_sent" & _
> > > > " AND EC_SQL = :sql_totalcount "

>
> > > > Dim cmd As New OracleCommand(sqltorun, myConnection)

>
> > > > Try
> > > > cmd.Connection.Open()
> > > > Catch ex As Exception
> > > > MsgBox("Please close the program and reopen to establish a
> > > > new connection and if it happens again call MIS" + export_date,
> > > > MsgBoxStyle.OkOnly, title)
> > > > End Try

>
> > > > 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"

>
> > > > Try 'go and get the export number if false no query has been run
> > > > before

>
> > > > export_num = cmd.ExecuteScalar

>
> > > > When i get to this step i get illegal number or vairable as the
> > > > exception.
> > > > This sql code works just fine when i run it in sql plus or toad.
> > > > Thanks for your help.- Hide quoted text -

>
> > > - Show quoted text -

>
> > Kerry,
> > When i do that i now get "conversion from type DBnull to string
> > is not valid" This tells me that the query is returning nothing. If
> > I change my code to look like this it returns the value I am looking
> > for:

>
> > Dim sqltorun As String = "select max(ec_export_number) from
> > event_campaign " & _
> > " where EC_PURPOSE
> > = :event_purpose AND EC_ITEM_SENT = :item_sent" & _
> > " AND EC_SQL = 'select cli_rid from dual' "

>
> > Dim cmd As New OracleCommand(sqltorun, myConnection)

>
> > Try
> > cmd.Connection.Open()
> > Catch ex As Exception
> > MsgBox("Please close the program and reopen to establish a
> > new connection and if it happens again call MIS" + export_date,
> > MsgBoxStyle.OkOnly, title)
> > End Try

>
> > '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"

>
> > Try 'go and get the export number if false no query has been
> > run before

>
> > export_num = cmd.ExecuteScalar- Hide quoted text -

>
> - Show quoted text -


No maybe i am saying this a little confusing. I have an application
that allows a user to export info from our database that the user can
choose the criteria he wishes and to track what they extracted i have
created a table that stores what SQL query they ran in the past. That
way if they run the same query in the future it tells them that they
ran this same query before by looking up the column that holds the sql
and comparing it what they are running at that time. So with that in
mind it isn't a subquery or at least i don't think it should be. Does
all that make sense?

 
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
How to bind variables everymn@yahoo.com Microsoft Access VBA Modules 5 21st Nov 2006 11:54 PM
Bind Variables Using ODP.NET vm.shinde@gmail.com Microsoft ADO .NET 0 24th Feb 2006 12:37 PM
BIND VARIABLES using 'Like' in the sql RDS Microsoft ADO .NET 1 18th Aug 2005 07:03 PM
Bind variables in vb.net RDS Microsoft VB .NET 3 18th Aug 2005 06:43 PM
Is there a way to bind form variables? dave Microsoft VB .NET 0 18th Nov 2003 08:27 PM


Features
 

Advertising
 

Newsgroups
 


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