selecting a table from a querystring

Results 1 to 4 of 4

Thread: selecting a table from a querystring

  1. #1
    Join Date
    Dec 1969

    Default selecting a table from a querystring

    i want to select a querystring and use it to select the table to read from.<BR><BR>MY CODE:<BR>&#060;%<BR>tblname=request.querystring("p roduct") <BR>SQL_query="SELECT * FROM "&tblname <BR>Set RSbrands = MyConn.Execute(SQL_query)<BR>%&#062;<BR><BR><BR>if i have a space ( cards) in the querystring why doesn&#039;t it work?? but it works without a space, ...but i need the space!

  2. #2
    J. Paul Schmidt Guest

    Default Don't Let Your QueryString Get Spaced Out

    So that a querystring can handle odd characters such as spaces, it&#039;s a good idea to use the Server.URLEncode() function on the value going in.<BR><BR>So instead of the following:<BR>"" & myprodvariable<BR><BR>Perhaps use the following:<BR>"" & Server.URLEncode(myprodvariable)<BR><BR>Best regards,<BR>-Paul<BR><BR>J. Paul Schmidt, MBA<BR>Databases on the Web<BR>

  3. #3
    Join Date
    Dec 1969

    Default Assuming the querystring is okay...

    ...that is, assuming that your ASP page *is* getting the querystring with the space (which Mr. Schmidt was *NOT* assuming, but I will), then the solution is the same as if you typed in the entire SQL SELECT: You need [...] around the table name! ANY TIME you have a space or any non-alphanumeric character in a field or table name...or any time you use a reserved word for a field or table must enclose the name in [...]. Simple as that!<BR><BR>Oh...and it *never* hurts to put the name in [...], so why not always do it in your code:<BR><BR>&#060;%<BR>tblname=request.querystrin g("product") <BR>SQL_query="SELECT * FROM [" & tblname & "]"<BR>Set RSbrands = MyConn.Execute(SQL_query)<BR>%&#062;<BR><BR>

  4. #4
    Eddie Campbell Guest

    Default Adding to what Bill says

    Why not solve the root cause of your problem and rename your data tables to sensible names WITHOUT spaces. The same goes for your field names.<BR><BR>&#060;Rant&#062;<BR>It is a shame that Microsoft and others allow you to spaces in at all. It just makes it more likely that you will have problems. Your life would be made easier if you stick to one of the table/field/variable etc. naimng conventions. For an example read this article:<BR><BR>&#060;/rant&#062;

Posting Permissions

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