I query my database and store the query results in a variable, then I compare that variable to the expected result and pass/fail based on the comparison (code below).
The problem is, when I store that queried result in the variable, it stores it with a chr(13) at the end. So "Magazine" becomes "MagazineCHR(13)". When I compare the two strings, the comparison fails.
I know how to remove the unwanted chr(13), but what I'm trying to find out is why is it there to begin with?
I know the data in the database does NOT contain the chr(13) so it is getting added to my string by QTP, but I don't know why.
'I created and set oConn earlier as an ADODB database connection object. It works just fine for all my queries.
'Verify How You Heard About Us
SQLstatement = "Select Source from OrderTable where OrderNumber = '123'"
Set ResultSet = oConn.Execute(SQLstatement)
varHeardAbout = CStr(ResultSet.GetString)
varExpected = DataTable("HearAboutUs", dtLocalSheet)
If UCase(Trim(varHeardAbout)) = UCase(Trim(varExpected)) Then
Reporter.ReportEvent micPass, "Stuff", "Stuff"
Reporter.ReportEvent micFail, "Stuff", "Stuff"
I have found nothing on this site, nor in the QTP help, nor even on a couple ADO dev websites that gives me any answers.
So where does the errant chr(13) come from? Why is it there? Am I doing something wrong? Is there some way to rewrite that code so it won't include the chr(13)? Or am I just supposed to expect it and handle it myself?
"The last 10% of any software project will take 90% of the budgeted time. The first 90% will take the other 90%"
"Source" means- the name of column.
Ex: Id - is the name of the column.
Nothing is permanent in this world.
But, that POWER (Who/what is it?) makes us to believe this is Eternal. It makes us good/bad things. I also believe that this is permanent universe. So I should work my job/service to others. No one is good/bad on this according to our knowledge. That power??? makes all these.
GetString is to get the whole recordset in a string or a single row as a string. That's why you see a delimiter. You had it working because your query resulted only in a single column and a single row and that why you never saw the main issue.