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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using databses with javascript problems

Status
Not open for further replies.

leearach2004

Technical User
Dec 8, 2005
86
GB
Hi there i have set of javascript funtions that call information from a database

I am using a where clause in my sql statment

this works fine when checking a field in the database that is a number but if i want to check a field in the database that is a text field it doesnt wotk

here is the funtion

function get_fyp() {

var data = new Array()
//select record number
id = "1";

//select record from database
var rs = new ActiveXObject("ADODB.Recordset")
rs.open("SELECT * FROM fyptext WHERE ID = " + id, conn, adOpenDynamic, adLockOptimistic)
rs2arr(rs, data)
rs.close()


// Read the resulting transaction state into the form
document.getElementById("fyp_subject").value = data["subject"]
document.getElementById("fyp_description").value = data["description"]
}

this all works fine as it is but if i want to change the variable id to somthing like

id="IT DEP";

assuming that the id field in the database is now set to text and contains the word IT DEP it doesnt work the error say no value given for one or more required paramiters

I dont understand why as all i am doing is using the WHERE statment with text insted of a number

anyone have any ideas id be most greatful

lee
 
Try this change:
Code:
      rs.open("SELECT * FROM fyptext WHERE ID = [COLOR=red]'[/color]" + id [COLOR=red]+ "'"[/color], conn, adOpenDynamic, adLockOptimistic)
I think the problem is that you need to include strings in quotes: ' ' (but not so with numbers).

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
hi there thanks for the info

you where correct strings have to have extra quotes

thanks very much

lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top