« Back to IP Phone Services Questions

ADO Select query problem

Combination View Flat View Tree View
Threads [ Previous | Next ]
ADO Select query problem
sql 2008 ado query eof recordset
Answer
12/27/11 6:51 PM
I am writing a time clock app; this part of the code checks last transaction for type (in/out) so they don't try to punch in w/o punching out, or vice versa.
Working with the clock out routine.
 
Successful IF there is a previous record in the database; however, if this is their first transaction, I am unable to resolve.
Please review code below and see if you can identify a solution.  Any help is GREATLY appreciated.
Cindy
 
//Is the person is trying to punch out w/o punching in?

    var input=Request.QueryString("input"); //comes from the Phone Input (previous page)
    var Conn = Server.CreateObject("ADODB.Connection");

    var RS = Server.CreateObject("ADODB.Recordset");
    var sql2;
    var str;
   
    Conn.Open("Provider=SQLNCLI10;Data Source=xxx;Persist Security Info=False;Initial Catalog=IPTimeClock;Uid=xxx;Pwd=xxx;");
   
    sql2=("SELECT Type FROM dbo.tblTransactions WHERE TransID=(SELECT MAX(TransID)from dbo.tblTransactions WHERE UserID="+input+")");
    RS.CursorType=2;
    RS.Open(sql2, Conn);
    str=RS("Type");
   
    if (RS.EOF == true and RS.BOF == true)
    {
        Clockout(input);
    }else
    {
    RS.MoveFirst();
   
    if (str="O")
    {
    Response.Write("<CiscoIPPhoneText>\r\n");
    Response.Write("<Title>IP Time Clock</Title>");
    Response.Write("<Text>You are currently clocked OUT.\r\n  Please Clock In First.</Text>\r\n");
    Response.Write("</CiscoIPPhoneText>\r\n");
    }
    else{Clockout(input);}
    }
   
    //RS.close;
    //Conn.close;
    //RS=null;
    //Conn=null;

Hy Cindy,
 
What about to count this here
 
"SELECT Type FROM dbo.tblTransactions WHERE TransID=(SELECT MAX(TransID)from dbo.tblTransactions WHERE UserID="+input+")"
 
and if the count is zero then there was no transaction
 
cheers Floh

Thank you, Florian, for your advice. The only way I was able to resolve was by changing the end of my query to UserID = "+input+" or 0 - and adding a default record with 0 as the ID. I do appreciate the assistance.