Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate data

Status
Not open for further replies.

cwolgamott

Programmer
May 29, 2002
69
US
Hello. :) I am creating some pages in Dreamweaver UltraDev to allow users to be able to add, modify and delete records in a database. I would like the user to be able to add records to a database (such as name, location, etc.), but I need to check whether the name already exists in the database. However, I am unsure of how to figure this out. I would greatly appreciate any suggestions or if someone could point me in a direction to where I might be able to find the answer. Thank you very much. :)
 
i'm not familiar with dreamweaver, but using asp you can run a sql statement to check for an existing record. for example, if you stored user info in a table called "tbl_users" and you had an asp page with a form with a "userName" text input element and you had a recordset object of "rs" and a connection object of "conn", then....

Code:
strSQL = "SELECT userName FROM tbl_users WHERE userName = '" & request("userName") & "'"

rs.open strSQL, conn
if rs.eof
  'no record found, meaning new entry is not a duplicate
  'and can be added.
else
  'record found, so entry already exists.
end if

glenn
 
Hello. :) Thank you so much for your response. I did end up deciding to use straight ASP instead of Dreamweaver. It ended up being much easier. However, I am still unable to solve my problem. I create a Select statement like the one you show:

SQL = SQL + " SELECT DeptName From department WHERE DeptName = '" & inputDeptName & "'"
Set rsDeptName=conn.Execute(SQL)

When I try to run this statement, however, it will error out if I try to run another instead of printing an error message like the following:

SQL = SQL + " INSERT INTO department (department.DeptID, department.DeptName, department.Location, department.Communication, department.BestTime, department.WorstTime, department.Strength, department.Weakness, department.Responsibility1, department.Responsibility2, department.Responsibility3, department.Responsibility4, department.Responsibility5, department.Suggestion1, department.Suggestion2, department.Suggestion3, department.Suggestion4, department.Suggestion5) "
SQL = SQL + "VALUES (" + CStr(depID) + ", " + "'" + inputDeptName + "', " + "'" + inputLocation + "', " + "'" + inputCommunication + "', " + "'" + inputBestTime + "', " + "'" + inputWorstTime + "', " + "'" + inputBestThing + "', " + "'" + inputBiggestThing + "'," + "'" + inputResponsibility1 + "', " + "'" + inputResponsibility2 + "', " + "'" + inputResponsibility3 + "', " + "'" + inputResponsibility4 + "', " + "'" + inputResponsibility5 + "', " + "'" + inputSuggestion1 + "', " + "'" + inputSuggestion2 + "', " + "'" + inputSuggestion3 + "', " + "'" + inputSuggestion4 + "', " + "'" + inputSuggestion5 + "')"
Response.write SQL
conn.Execute(SQL)

Else

errorArea = errorArea + "The profile that you have entered already exists. Please press the back button and try again."

End If

I would greatly appreciate any suggestions or comments that you might have. Thanks again for your reply.
 
i'm not sure i follow your reply. if i understand correctly, you're saying that the first sql statement runs fine, but that the second one doesn't.

could there be some syntax error in your sql statement. why do you have the "sql" string set with "sql = sql +"? is something else being added beforehand? unless you're trying to build some larger sql string, it should simply be "sql =".

also, i just noticed, you need to use "&" to join/build strings, not "+". easy thing to mess up on when switching between javascript and vbscript.

glenn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top