Question

ASP SQL With Dynamic Queries

Asked by: smyers051972

Hi,

I have a dynamic query in sql that is used to add data to a database. I am trying to build a simple ASP based web page that will have a form used to add this data.  The problem I have is how to submit these variables and pass them to the query.  I am going to attach my query in hopes of gaining assistance figuring these out as I am very new to ASP programming.

Thanks again and as always if any questions dont hesitate to ask :)

After the recent changes on the site I am unable to use the Attach code feature but can attach files here it is.

  • code.txt
    • 1 KB

    Unable to attach code so here it is

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-11-06 at 08:36:51ID24878411
Tags

ASP SQL 2000 Dynamic Queries

Topics

Active Server Pages (ASP)

,

Databases Miscellaneous

Participating Experts
3
Points
500
Comments
20

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. ASP and SQL
    At present I run Access and ASP. ASP is slow when multiple users use it To speed things up will it help to have an SQL database on a sever that runs Access 97? If not I will need to find a cheap SQL provider! Paul
  2. ASP
    I have a situation where I have a user fill out a form. When they click the Submit button, I call an ASP page that first checks a SQL database. After the database is checked, I want to throw up a dialog box to ask them a yes/no question, which can only be achieved using a c...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Allister_ReidPosted on 2009-11-06 at 08:53:40ID: 25760808

Hi,
Are you using ASP.Net with code-behind?  Visual Basic? C#?



Regards

 

by: smyers051972Posted on 2009-11-06 at 09:26:14ID: 25761089

Just basic ASP, trying to learn that and possibly ASP .NET too.  

What I have so far is something like this but i know the code wont work right:
<%
Dim Connection
Dim ConnString
Dim Recordset
Dim SQL

ConnString="DRIVER={SQL Server};SERVER=SQLVM;UID=sa;" & _
"PWD=password;DATABASE=sourcetracking"

SQL = ?????????????????????

Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")

Connection.Open ConnString

Recordset.Open SQL,Connection

Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
%>

 

by: smyers051972Posted on 2009-11-06 at 09:35:13ID: 25761158

Outside of ASP mostly HTML. I have not figured out PHP with ASP yet. So for now I am going with HTML.

 

by: Allister_ReidPosted on 2009-11-06 at 09:41:19ID: 25761204

I'd recommend you cut out ASP classic entirely and go straight to ASP.Net, unless you absolutely have to!

You'll need to create the SQL as a stored procedure (http://msdn.microsoft.com/en-us/library/aa258259%28SQL.80%29.aspx) and then, if you are sticking with ASP classic do something like the following: http://blog.binarybooyah.com/blog/post/Classic-ASP-data-access-using-parameterized-SQL.aspx

 

by: smyers051972Posted on 2009-11-06 at 09:45:29ID: 25761242

I would have to use the SQL embedded because if I need to make stored proc's it will be a huge task getting change requests filled out and approved by 10 people in the company LOL. I will read the links as well and appreciate any further attention.

 

by: Allister_ReidPosted on 2009-11-06 at 09:55:14ID: 25761329

That second link I provided shows how to create a SQL Command object with inline SQL rather than an SP; use this object for assigning the parameters - it is a lot safer than adding values directly.

 

by: samic400Posted on 2009-11-06 at 11:43:11ID: 25762393

Are you passing in values from a form or querystring?

 

by: samic400Posted on 2009-11-06 at 11:50:22ID: 25762444

'you wouldn't need a recordset - just a basic example below

<%
Dim Connection
Dim ConnString
Dim SQL
Dim mField1
Dim mField2

'let's pretend that mField1 is a customer and the form name was named customer
'let's pretend that mField2 is a phone number and the form name was named phone

mField1 = request.form("customer")
mField2 = request.form("phone")

ConnString="DRIVER={SQL Server};SERVER=SQLVM;UID=sa;" & _
"PWD=password;DATABASE=sourcetracking"

Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open ConnString

'now let's say in SQL Server, your table is called tblCustomer and your customer field is named cust
' and your phone field is named phonenumber
'
' you wanted to add a record or "insert" a record

SQL = "insert into tblCustomer (cust,phonenumber) values('" & mField1 & "','" & mField2 & "')"

Connection.Execute SQL

Connection.Close
Set Connection=nothing
%>

 

by: samic400Posted on 2009-11-06 at 11:52:41ID: 25762456

The example above is coming from a form that is submitted - this example is using querystring - for example - www.xxx.com?customer=bob&phone=123456

'using same code above
<%
Dim Connection
Dim ConnString
Dim SQL
Dim mField1
Dim mField2

mField1 = request.querystring("customer")
mField2 = request.querystring("phone")

ConnString="DRIVER={SQL Server};SERVER=SQLVM;UID=sa;" & _
"PWD=password;DATABASE=sourcetracking"

Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open ConnString

'now let's say in SQL Server, your table is called tblCustomer and your customer field is named cust
' and your phone field is named phonenumber
'
' you wanted to add a record or "insert" a record

SQL = "insert into tblCustomer (cust,phonenumber) values('" & mField1 & "','" & mField2 & "')"

Connection.Execute SQL

Connection.Close
Set Connection=nothing
%>

 

by: Allister_ReidPosted on 2009-11-06 at 11:57:20ID: 25762492

'Hi,
'what about the case of:

mField1 = "';go;drop database sourcetracking; go;"

'?

'Regards

 

by: samic400Posted on 2009-11-06 at 12:02:46ID: 25762540

Allister_Reid - that is a true point but and I agree - stored procedures is the way to go - to avoid the SQL injection scenario that you mention above

- but he is looking for an answer to solve his problem and in simpliest terms, this will work.

 

by: smyers051972Posted on 2009-11-06 at 12:02:56ID: 25762544

For me that wont be an issue the user name it will actually run under will be read only plus not a publicly accessible site.

 

by: smyers051972Posted on 2009-11-06 at 12:03:29ID: 25762552

i mean a user who cant drop db sorry!!! lol

 

by: smyers051972Posted on 2009-11-06 at 12:25:46ID: 25762733

When you have a 300+ line query in SQL to use with basic ASP isnt there an easier way to do the statement when embedding the code into the script?

 

by: samic400Posted on 2009-11-06 at 12:30:54ID: 25762767

The easiest way would be to create a stored procedure and pass the variables to it and let SQL Server do all the work for you. You would have to create a Command object in ASP, and define the parameters to use it.

 

by: carrzkissPosted on 2009-11-06 at 12:57:59ID: 25762986

smyers051972
Please have a look at this.
http://ee.cffcs.com/Q_24816556/BilletScanDefects4_F.asp
code
http://ee.cffcs.com/Q_24816556/Q_24816556.zip

Things it will teach you:

#1: Display Records from a Query run against a SQL Statement
#2: Paging through multiple records (Like that is Google Search)
#3: Insert new records
#4: Update existing Records
#5: How to use Parameters to help stop SQL INJECTION and Drops.

This is the best example that I can think of to show you what you will need to do in order to accomplish your goals of programming in ASP/SQL

And to add to this.
PHP is a Language like ASP/SQL is. It is not a form of HTML.
So, using HTML is in everything that you do, rather it is ASP, PHP, PERL, CGI
All deal with HTML.
So, learning HTML along side your programming in ASP Classic (or) ASP .NET
Is essential in getting your sites up and running on a professional basis.

Good Luck and hope this will help you to learn how to accomplish your needs and goals.

Carrzkiss

 

by: carrzkissPosted on 2009-11-06 at 13:01:10ID: 25763014

Here is another example that I have up as well.
http://www.experts-exchange.com/Q_24801116.html

Good Luck
Carrzkiss

 

by: smyers051972Posted on 2009-11-09 at 10:54:45ID: 31651095

Thank you!

 

by: carrzkissPosted on 2009-11-09 at 10:59:11ID: 25778820

You are so very welcome.
I will be adding these demo's to a new site that I am working on, along with a LOT of other projects.
So keep an eye on my profile for more information to become available.

Have a good one
Carrzkiss

 

by: smyers051972Posted on 2009-11-09 at 11:00:49ID: 25778839

I opened another case for something of almost the same nature but it is a separate issue...

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...