Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 October 14th, 2004, 09:50 AM
Authorized User
 
Join Date: Sep 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Converting asp/vbscript code to asp.net

I am in the process of converting some of my asp/vbscript code to asp.net. I have been stuck on one particular piece for a little while now.

I have an app that displays a dataset with 2 select boxes -"ItemNumber" and "Species", which allow the user to "filter" the results to their liking. I needed to provide the functionality that would allow the user to select 1 or both of the boxes if so desired.
Here is an example of one of the vbscript code snippets driving the "Species" select box in the asp page:

sql = "SELECT * From vw_cat2 "


If Not IsEmpty(Request("Species")) Then
Dim strSpecies
strSpecies = Trim(Request("Species"))
If strSpecies <> "" Then
If blnWhere Then sql = sql & "AND " Else sql = sql & "WHERE " : blnWhere = True
If (Left(strSpecies, 1) = "*" And Len(strSpecies) > 1) Then
sql = sql & "(Species LIKE '%" & Replace(Mid(strSpecies, 2), "'", "''") & "') "
ElseIf (Right(strSpecies, 1) = "*" And Len(strSpecies) > 1) Then
sql = sql & "(Species LIKE '" & Replace(Mid(strSpecies, 1, Len(strSpecies)-1), "'", "''") & "%') "
Else
sql = sql & "(Species = '" & Replace(strSpecies, "'", "''") & "') "
End If
End If
End If

The best I have been able to come up with in asp.net is:

MyCommand = New SqlDataAdapter("select ItemNumber, Species, stdprice, Location from vw_cat2 where Species='" & Species.SelectedItem.Value & "' and ItemNumber='" & ItemNumber.SelectedItem.Value & "'", myConnection)

However this does not provide me the 'and/or' flexibility I need. If a user selects a "Species" but not an "ItemNumber" I want to test for 'where' in that situation.

Andy advice would be appreciated.

Thanks!

 
Old October 14th, 2004, 03:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Use a data view, use the following select:

select ItemNumber, Species, stdprice, Location from vw_cat2

Then use the RowFilter property to specify the species or itemnumbre filter:

Dim vw as dataview = ds.tables(0).defaultview
vw.RowFilter = "Species = '" & <variable> & "' and ItemNumber = '" & <variable & "'"

Only include the row filter properties that you want. Then you can bind whatever to the dataview.

Brian
 
Old October 15th, 2004, 01:10 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The code that you use to determine what to include in your SQL query shouldn't be a whole lot different from what you had in ASP/VBScript. The logic is entirely the same, the difference is that you are working with server controls instead of having to interrogate the request object directly. Otherwise, it should be close to identical.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Classic Asp to Asp.Net 2.0 vikaspatyal ASP.NET 2.0 Professional 2 October 7th, 2007 06:33 PM
vbscript in asp.net 2.0 ufdylan ASP.NET 2.0 Basics 3 August 14th, 2007 12:02 PM
converting vbscript to asp willee ASP.NET 1.0 and 1.1 Basics 1 September 8th, 2006 07:36 AM
Converting code to VBScript Thomas82 Classic ASP Professional 2 July 30th, 2006 07:28 AM
Converting asp code to com altaf Classic ASP Components 1 December 6th, 2004 01:35 AM





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