473,383 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

ASP.NET Include local variable in Oracle Select Statement

13
Hello,

How do I insert a local variable into a select statement when using the Oracle DB connecter in asp.net 2.0

Expand|Select|Wrap|Line Numbers
  1. In Code Behind:  I set this the string to be the users id:
  2.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  3.         Dim strNTUser As String
  4.         Dim iPos As Integer
  5.         strNTUser = RTrim(Request.ServerVariables("LOGON_USER"))
  6.         iPos = Len(strNTUser) - InStr(1, strNTUser, "\", CompareMethod.Binary)
  7.         strNTUser = Right(strNTUser, iPos)
  8.     End Sub
  9.  
  10. In ASP I try to use the value of strNTUser as the where clause condition:
  11. <asp:SqlDataSource ID="oraDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:oraDB %>" ProviderName="<%$ ConnectionStrings:oraDB.ProviderName %>" SelectCommand='SELECT * FROM "MY_ASSOCIATES" WHERE ("USERID" = :USERID)'>
  12.         <SelectParameters>
  13.             <asp:SessionParameter Name="USERID" SessionField="strNTUser" Type="String" />
  14.         </SelectParameters>
  15.  
  16.  
When I run this, I get no result. as the USERID doesn't seem to be fetting set. I realize that I'm probably doing something silly with this but I'm rather new with ASP.net and I'm trying to understand wherre I'm going wrong. Thanks for your help.
Jul 16 '07 #1
8 6047
jinksto
13
Hello,

How do I insert a local variable into a select statement when using the Oracle DB connecter in asp.net 2.0


In Code Behind: I set this the string to be the users id:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strNTUser As String
Dim iPos As Integer
strNTUser = RTrim(Request.ServerVariables("LOGON_USER"))
iPos = Len(strNTUser) - InStr(1, strNTUser, "\", CompareMethod.Binary)
strNTUser = Right(strNTUser, iPos)
End Sub

In ASP I try to use the value of strNTUser as the where clause condition:
<asp:SqlDataSource ID="oraDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:oraDB %>" ProviderName="<%$ ConnectionStrings:oraDB.ProviderName %>" SelectCommand='SELECT * FROM "MY_ASSOCIATES" WHERE ("USERID" = :USERID)'>
<SelectParameters>
<asp:SessionParameter Name="USERID" SessionField="strNTUser" Type="String" />
</SelectParameters>



When I run this, I get no result. as the USERID doesn't seem to be fetting set. I realize that I'm probably doing something silly with this but I'm rather new with ASP.net and I'm trying to understand wherre I'm going wrong. Thanks for your help.
I've also tried using other methods. What should I select in the Add WHERE clause dialog for "Source:" in order to do this? Control, Cookie, Form, Profile, Querystring, Session? Lacking solid information I selected "Session" but I think that is probably for Session Variables. Not sure what to put there in order to use a derived variable in the SQL string.
Jul 16 '07 #2
Plater
7,872 Expert 4TB
I am not positive but maybe something like:

Expand|Select|Wrap|Line Numbers
  1. <asp:SqlDataSource ID="oraDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:oraDB %>" ProviderName="<%$ ConnectionStrings:oraDB.ProviderName %>" SelectCommand='SELECT * FROM "MY_ASSOCIATES" WHERE ("USERID" = <%=strNTUser  %>)'>
  2.  
Jul 16 '07 #3
jinksto
13
hi, thanks for your response. If I do that I get:

ORA-00936: missing expression

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OracleClient.OracleException: ORA-00936: missing expression

I really only want to inject the value off strNTUser into the SQL string. You would think that this would be a rather easy thing to do but I'm failing to grasp some core concept.
Jul 16 '07 #4
Plater
7,872 Expert 4TB
You could always create the whole object in the code side and not in the asp-page
Jul 16 '07 #5
jinksto
13
You could always create the whole object in the code side and not in the asp-page
While I appreciate the elegance, that seems like a long way to go just to add a single value to the parameter string.
Jul 16 '07 #6
jinksto
13
I am not positive but maybe something like:

Expand|Select|Wrap|Line Numbers
  1. <asp:SqlDataSource ID="oraDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:oraDB %>" ProviderName="<%$ ConnectionStrings:oraDB.ProviderName %>" SelectCommand='SELECT * FROM "MY_ASSOCIATES" WHERE ("USERID" = <%=strNTUser  %>)'>
  2.  

It seems like the strNTUser variable isn't getting set in the SQL. If I'm setting strNTUser in Page_Load event is it still in context when the ASP portion of the page runs? Here's where I create strNTUser:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strNTUser As String
Dim iPos As Integer
strNTUser = RTrim(Request.ServerVariables("LOGON_USER"))
iPos = Len(strNTUser) - InStr(1, strNTUser, "\", CompareMethod.Binary)
strNTUser = Right(strNTUser, iPos)
End Sub

And I'm not using it until much later in the ASP

<asp:SqlDataSource ID="oraDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:oraDB %>" ProviderName="<%$ ConnectionStrings:oraDB.ProviderName %>" SelectCommand='SELECT * FROM "MY_ASSOCIATES" WHERE ("USERID" = <%=strNTUser %>)'>

Am I even going in the right direction with this...?
Jul 17 '07 #7
Plater
7,872 Expert 4TB
I think you will need to make that varriable at the very least Page Global in order for the ASP side to use it.

I'm not sure though, I almost never do anything ASP side if I can help it.
Jul 17 '07 #8
jinksto
13
I think you will need to make that varriable at the very least Page Global in order for the ASP side to use it.

I'm not sure though, I almost never do anything ASP side if I can help it.
I found the issue, I needed to set the variable in the "selecting" event. In the end I created a function to return the LOGON_USER and called that from the selecting event to set the variable.

So technically, you were correct, the strNTUser was out of context in the place that I was trying to use it.
Jul 19 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Florian Marinoiu | last post by:
Hi, I have the following MS-SQL Server statement that I want to convert to ORACLE 8.1 SET @pPhone = '%' + @pPhone + '%' In ORACLE I tried SELECT '%' || pPhone || '%' into pPhone from dual; ...
11
by: Markus Breuer | last post by:
I have a question about oracle commit and transactions. Following scenario: Process A performs a single sql-INSERT into a table and commits the transaction. Then he informs process B (ipc) to...
7
by: Robert Brown | last post by:
Is there a way to use PreparedStatements (or bind variables) with SQL statements that have a variable number of arguments. For example, I have an array of IDs for employees of a certain type and I...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
4
by: Murph | last post by:
Hi, I'm new to ASP.NET and have a problem which i'm hoping will be easy to answer... i have only used VB, HTML and Flash up until now! I am designing an ASP page which uses OleDb to retrieve...
1
by: k_mahesh7 | last post by:
I need tp bind a variable to a select and send to oracle database. I have the value to be send in a variable but that variable to be binded to the query as the database I an hitting is a siebel...
3
by: RLN | last post by:
Re: Access 2003/Oracle 9i I have an Access app that connects to an Oracle DB via OLEDB/VBA code (no DSN or ODBC) Queries against straight Oracle tables run fine. For this query, however,...
0
by: becksinthecity | last post by:
I'm trying to convert the below SQL into Oracle but am having some issues with the variable declarations. SQL commands declare @sqlstring varchar(500) select @sqlstring= (select ...
15
Zwoker
by: Zwoker | last post by:
Hi all, I am accessing data from an Oracle database via a connect string. I got into the situation where I wanted to write my SQL select statement to do a join between a local table sitting in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.