Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 10th, 2007, 06:43 AM
Registered User
 
Join Date: May 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems with Select & Where statement

Hi

I am trying to get information in a Database to be displayed when a user is logged in using cookies. Unfortunately have seemed to have got stuck somewhere.

Please see the below code of where I have got to so far: -

<script runat="server">

Dim DBConnection As OleDbConnection
Dim DBCommand As OleDbCommand
Dim DBReader As OleDbDataReader
Dim SQLString As String
Dim UserNameCookie As HttpCookie

Sub Page_Load()

    If (Request.IsAuthenticated = true) Then
        pnlEdit.Visible = true
        pnlView.Visible = false
        lblStatus.Text = "<br>Welcome: " & _
        Request.Cookies("UserNameCookie").Value
       End If

    If Not Page.IsPostBack Then
    DBConnection = New OleDbConnection( _
      ConfigurationSettings.AppSettings("ConnectionStrin g"))
    DBConnection.Open()
    SQLString = "SELECT * FROM Customers" & _
        "WHERE CustomerEmail = '" & UserNameCookie & "'"
    DBCommand = New OleDbCommand(SQLString, DBConnection)
    DBReader = DBCommand.ExecuteReader()
    RepeaterDisplay.DataSource = DBReader
    RepeaterDisplay.DataBind()
    DBReader.Close()
    DBConnection.Close()
  End If

End Sub

I have declared the UserNameCookie as a HttpCookie but now getting an error on the page where Operator '&' is not defined for types 'String' and 'System.Web.HttpCookie'.

Does anyone have any suggestions or pointers of where I need to go from here?

Thanks

Sharon


 
Old June 10th, 2007, 02:39 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You need to read the value from the cookie and place that into a string and then add that string to your SQL statement.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old June 11th, 2007, 04:18 PM
Registered User
 
Join Date: May 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Thanks for the tip, becuase I am requesting the cookie value, I have now assigned it to the variable. For example:

Dim UserNameCookie As String
UserNameCookie = Request.Cookies("UserNameCookie").Value

Now I can use the variable UserNameCookie throughout my coding.

Thanks
Sharon


 
Old June 11th, 2007, 07:09 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You are welcome, glad it worked out for you.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
select statement ??? RinoDM SQL Server 2000 7 June 19th, 2008 08:40 AM
select Statement gregalb SQL Server 2000 3 January 15th, 2008 12:00 AM
Select from another select statement to a repeater simsen ASP.NET 2.0 Professional 0 May 2nd, 2007 04:34 PM
Select Into statement ashu_from_india Oracle 8 October 9th, 2005 11:30 PM
Select statement Sarju Mehta SQL Server 2000 1 March 30th, 2004 03:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.