Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 25th, 2010, 07:31 AM
Authorized User
Points: 150, Level: 2
Points: 150, Level: 2 Points: 150, Level: 2 Points: 150, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Location: Perth, Western Australia
Posts: 33
Thanks: 7
Thanked 1 Time in 1 Post
Send a message via MSN to cuddling101 Send a message via Yahoo to cuddling101
Question WHERE {field name passed as a parameter} 'contains' {value passed as a parameter}

My standard Grid View display, or LINQ display, of my primary database is just how I want it, but I want to be able to make it display different sets of records based on parameters passed to it from a 'calling' page.

Code:
SELECT [ID], [Title], [Series_Available], [Available], [Authors_UK], [Illustrators_UK], [Authors_USA], [Illustrators_USA], [Book_Numbers], [ISBNs], [Publication_Dates], [Front_Cover_JPEGs] FROM [Titles]
what I want to be able to then do is have the system generate a varying WHERE clause based on the two parameters of field to test, and value to test, so that for example on one call it might generate

WHERE Available 'contains' "A"

BUT on another occasion it might be called on to generate

WHERE Authors_UK 'contains' "Notkin"


Data commentary

The contents of Available is an up to 16 character string with one, some or all of the letters A to P, each letter occuring, if at all, only once.

The contents of Authors_UK is a string such as "Gulkin, S; Notkin, J. J."


Bottom line questions -

1. Is there a 'contains' operator, or a function that can be called to do that? If it is a function, how would I incorporate that call to the building of the WHERE clause?

2. Can I pass a field name as a parameter and, if so, how do I do it?


Caveat

If these questions are beyond the scope of the Beginning book and more the scope of the Professional book, I am very happy to buy that book, and look to find the answers there, or on the forum for that book. Please advise accordingly.

Best regards

Philip
Reply With Quote
  #2 (permalink)  
Old August 25th, 2010, 08:49 AM
Imar's Avatar
Wrox Author
Points: 72,042, Level: 100
Points: 72,042, Level: 100 Points: 72,042, Level: 100 Points: 72,042, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,081
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

It depends on where your data comes from. When using LINQ you can take a look at the Dynamic LINQ library: http://weblogs.asp.net/scottgu/archi...y-library.aspx

For a SqlDataSource you could habdle the Selecting event and change the CommandText:

Code:
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
  e.Command.CommandText+= " WHERE Description LIKE '%whatever%'";
}
Two things worth noting:

1. I am using LIKE with % symbols which acts like the contains you talked

2. Make sure you don't open your code for SQL injection. This dynamic nature of SQL statements make it easy to inject something like:

; DROP DATABASE MASTER; --

instead of the literal whatever, which would select all records from your table and then delete your master database. No fun.... ;-)

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old August 25th, 2010, 08:52 AM
Imar's Avatar
Wrox Author
Points: 72,042, Level: 100
Points: 72,042, Level: 100 Points: 72,042, Level: 100 Points: 72,042, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,081
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

BTW: these kind of questions are not necessarily beyond the scope of the book, but they are a bit off-topic. You're better off posting in a more general ASP.NET 4 forum like this one: http://p2p.wrox.com/asp-net-4-general-discussion-561/

Posting there will likely draw more attention to your questions, and makes this forum a bit more focused on the book.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass a control parameter and process a return parameter in sqldatasource jayshankar ASP.NET 2.0 Basics 1 January 1st, 2009 10:18 AM
How to passed an xsl parameter to a javascript fun jadeite100 XSLT 1 June 22nd, 2007 02:51 PM
Value in Querystring not being passed u_heet Classic ASP Professional 2 September 16th, 2004 07:15 AM
wrong passed parameter apek PHP How-To 1 January 11th, 2004 01:08 PM
All My Checkboxes are passed as "on", whether or n WebDevel Javascript How-To 1 December 9th, 2003 10:40 AM



All times are GMT -4. The time now is 12:27 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.