Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: asp.net help

  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,457
    Thanks
    15
    Thanked 0 Times in 0 Posts

    asp.net help

    I need help to do the following in asp.net (i'm an asp programmer not .net)

    1. open a mssql db (i have username,password,dbname)
    2. create an asp.net file which will take in a querystring (id)
    3. lookup in db that productnewid (select productnewid from products where productid=[id passed])
    4. create a 301 redirect to product.asp?p_id=459 (where 459 is the productnewid from the above)

    can someone please help me with this?
    (if it helps i can tell you how i would do in asp but i need this in .net to point to my asp page)

    if it helps i found code for the 301 redirect -- i just need the new productid from the db passed
    <script runat="server">
    private void Page_Load(object sender, System.EventArgs e)
    {
    Response.Status = "301 Moved Permanently";
    Response.AddHeader("Location","http://www.new-url.com/product.asp?p_id=22");
    }
    </script>
    Last edited by esthera; 03-08-2007 at 07:21 AM. Reason: addition

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Most important thing for us to know when you ask .net question is the version, as 2.0 has a lot of changes.

    So, 1.1 or 2.0?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,457
    Thanks
    15
    Thanked 0 Times in 0 Posts
    how can i know this from the current application

    i think it's 1.1

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    It's probably 1.1 You can verify in IIS.

    Here's a sample of a very simple query (gets only one value, no datasets or anything) against Northwind.

    Code:
    <%@ Page Language="VB" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.Configuration" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    
    <script runat="server">
    dim conn as SqlConnection
    dim result as int32
    dim connString as string = "server=xx.xx.xx.xx;database=Northwind;user id=sa;password=sa"
    
    Sub Page_Load
    	if not Page.IsPostBack then
    		try
    			dim sql as string = "select CategoryID from dbo.Categories where CategoryName=@name"
    			using conn As New SqlConnection(connString)
    				Dim cmd As New SqlCommand(sql, conn)
    				cmd.Parameters.Add("@name", SqlDbType.VarChar)
    		        cmd.Parameters("@name").Value = "condiments"
    				conn.Open()
    				result = Convert.ToInt32(cmd.ExecuteScalar())
    				lblText.Text = result.ToString()
    			end using
    		catch e as Exception
    			lblText.Text="Exception: " + e.Message
    		end try
    	end if
    End Sub
    
    </script>
    <html>
    <head>
    <title> New Document </title>
    </head>
    
    <body>
    <asp:Label ID="lblText" runat="server" />
    </body>
    </html>

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •