View Single Post
  #3 (permalink)  
Old September 8th, 2005, 01:49 AM
joefawcett's Avatar
joefawcett joefawcett is offline
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Is this running server-side or client-side?
Aside from the fact that the path is not well-formed, unless "db" was a typo for "d:" then either, if server-side:
Code:
function dblookup()
{
    var myConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=d:\\sdi.mdb"; 

    var ConnectObj = Server.CreateObject("ADODB.Connection");
    var RS = Server.CreateObject("ADODB.Recordset");
    var sql="SELECT * FROM employeespulled WHERE empid='1';";

    ConnectObj.Open (myConnect);
    RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText);

    var fieldCount = RS.Fields.Count;
    Response.Write ("Field Count" + fieldCount);
    RS.Close();
    ConnectObj.Close();
}
Client-side (security settings will need to be set to allow unsafe ActiveX initialisation, database must be on client in D: drive root).
Code:
function dblookup()
{
    var myConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=d:\\sdi.mdb"; 

    var ConnectObj = new ActiveXObject("ADODB.Connection");
    var RS = new ActiveXObject("ADODB.Recordset");
    var sql="SELECT * FROM employeespulled WHERE empid='1';";

    ConnectObj.Open (myConnect);
    RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText);

    var fieldCount = RS.Fields.Count;
    alert("Field Count" + fieldCount);    
    RS.Close();
    ConnectObj.Close();
}
Are you sure empId is a text field not an integer? If an integer you don't need quotes around the value?
You should also test for the recordset having any rows at all before reading data:
Code:
if (RS.BOF && RS.EOF)
{
  //No data
}
Finally you need to make sure the constants such as adCmdText are defined somehow in the page.



--

Joe (Microsoft MVP - XML)
Reply With Quote