Advertisement

03.27.2006 at 04:22AM PST, ID: 21790081
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Adding to database, preventing duplicates

Asked by luna621 in Active Server Pages (ASP)

Tags: ,

Hello, I'm just starting to learn ASP and Javascript.  I was testing out Riccardi's BigHit Video website, and was able to add customers into the database nicely.  However, when I try to add an employee things start getting messy.  I basically took the adding of a customer, and modified it to add a new employee.  The customer's ID number was based on adding 1 to the largest ID already in the database.  The ID for employees is their SSN, which has to be unique.  I was trying to write code to make it check for duplicate SSNs, but it is giving me an error.  Please guide me through this, and let me know my error.  This is what the computer gives me:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'ssn='.
/bighit/bighittools.js, line 141

...

function lookupCustomer(conn, id) {
   var customerSQL="select * from Customer where accountId="+id;
   var custSet = conn.Execute(customerSQL);
   // check to see if any row was returned
   var customer = new Object();
   customer.accountId = new String(custSet("accountId"));
   customer.firstName = new String(custSet("firstName"));
   customer.lastName = new String(custSet("lastName"));
   customer.street = new String(custSet("street"));
   customer.city = new String(custSet("city"));
   customer.state = new String(custSet("state"));
   customer.zipcode = new String(custSet("zipcode"));
   return customer;
}

function lookupEmployee(conn, id) {
   var employeeSQL="select * from Employee where ssn="+id;
   var emplSet = conn.Execute(employeeSQL);  // <------------------------------------ line 141, error is pointing to this.  Why?
   // check to see if any row was returned
   var employee = new Object();
   employee.ssn = new String(emplSet("ssn"));
   employee.firstName = new String(emplSet("firstName"));
   employee.lastName = new String(emplSet("lastName"));
   return employee;
}

...

--------------------------------------------------------------------------------------------------------------------------------------
CODE:
--------------------------------------------------------------------------------------------------------------------------------------

<%@LANGUAGE="JScript"%>
<!-- makeemployee.asp -->
<html>
   <!-- #include file="bighittools.js" -->
   <%
   startApplication("makeemployee.asp");
   // get parameter values
   var employee;
   employee = makeEmployee(Request);
   with (employee) {
      printHeader("New Employee Receipt","Welcome "+firstName+" "+lastName);
      // connect to database
      conn = Server.CreateObject("ADODB.Connection");
      conn.Open("BigHitVideo");
      // check for duplicates
      dupId = conn.Execute("select ssn from Employee");
      dupId = executeSQL("select ssn from Employee");

   employee = lookupEmployee(conn,dupId);
   if (employee.ssn == dupId) {// no new employee
      Response.Write("<br>Cannot add duplicate employee.<p>\n");
      endApplication("makeemployee.asp")
   }

      // insert employee
      newEmplSQL = "insert into Employee "
         +"(ssn, firstName, lastName)"
         +" values("
         +sqlString(ssn)+", '"
         +sqlString(firstName)+"','"
         +sqlString(lastName)+"')";
      //Response.write("<br>SQL: "+newEmplSQL+"<br>");
      //conn.Execute(newEmplSQL); // replaced with function call
      executeSQL(newEmplSQL);
   } // end with employee
   // fetch employee information from the database
   employee = lookupEmployee(conn,ssn);
   if (employee.ssn != ssn) {// no new employee
      Response.Write("<br>No new employee with account ID: "+ssn+"<p>\n");
      employee = makeEmployee(Request);
   }
   printEmployeeTable(employee);
   printFooter("addemployee.asp");
   endApplication("makeemployee.asp");
%>
</html>

--------------------------------------------------------------------------------------------------------------------------------------

Thank you.Start Free Trial
[+][-]03.27.2006 at 05:23AM PST, ID: 16299863

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.27.2006 at 05:56PM PST, ID: 16307006

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.27.2006 at 06:21PM PST, ID: 16307097

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.27.2006 at 06:23PM PST, ID: 16307101

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.27.2006 at 06:31PM PST, ID: 16307130

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.27.2006 at 06:55PM PST, ID: 16307247

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.28.2006 at 12:56AM PST, ID: 16308771

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Active Server Pages (ASP)
Tags: bighit, bighitvideo
Sign Up Now!
Solution Provided By: carl_tawn
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.28.2006 at 01:21AM PST, ID: 16308856

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32