View Full Version : asp.net help

03-08-2007, 06:47 AM
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";

03-08-2007, 10:59 PM
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?

03-09-2007, 06:32 AM
how can i know this from the current application

i think it's 1.1

03-09-2007, 03:47 PM
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.

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

<title> New Document </title>

<asp:Label ID="lblText" runat="server" />