Driver.ColumnCount only works when debugging
Here's my code:
function testve() { var csvPath = "C:\\TestData\\FrameFields.csv"; QueryCSVByID(csvPath,"FrameFields.csv",1); } function QueryCSVByID(csvPath,csvName,testID) { let colCount = 0; let Driver = DDT.CSVDriver(csvPath); if (testID == -1) { //var queryAll = `Select * from JobEntryData.csv`; var queryAll = 'Select * from ' + csvName + ''; Driver.ADOCommandObject.CommandText = queryAll; } else { var queryByID = 'SELECT * FROM ' + csvName + ' WHERE TestID =' + '"' + testID + '"' + ''; Driver.ADOCommandObject.CommandText = queryByID; //aqUtils.Delay(10000) } //aqUtils.Delay(10000); colCount = Driver.ColumnCount;<-Fails at runtime, unless I'm debugging. while(!Driver. EOF()) { for(var i = 0; i < colCount - 1 ;i++) { Log.Message("Column " + i + " name is " + Driver.ColumnName(i) + " and it's value is " + Driver.Value(i)); } Driver.Next(); Log.Message("---------------------------- ROW --------------------------------------------") ; } }
Driver.ColumnCount gets the following error at runtime:
Unless I'm in debug mode. Then it works fine.
I tried adding 10 second delays because I wasn't sure if it was just taking time to get the results. Didn't work.
Thoughts anyone?
OK, first of all, if TestID is -1, you don't need to declare the SQL query.. the assumption is that, if you don't alter the command text, it's always going to be a select all. So, I'd simply do an if then to check if TestID != -1... if that returns true, set the query, otherwise, do nothing but continue with your test.
So... my guess is that, in debugging, TestID is -1... so, you never set your SQL query to the queryByID SQL statement. Hence, you'll not get the error... because my guess is that you're running an SQL query for a column called TestID that is an integer and not a string... so, that's the type mismatch. Try the following code:function testve() { var csvPath = "C:\\TestData\\FrameFields.csv"; QueryCSVByID(csvPath,"FrameFields.csv",1); } function QueryCSVByID(csvPath,csvName,testID) { let colCount = 0; let Driver = DDT.CSVDriver(csvPath); if (testID != -1) { var queryByID = 'SELECT * FROM ' + csvName + ' WHERE TestID = ' + testID + '; Driver.ADOCommandObject.CommandText = queryByID; //aqUtils.Delay(10000) } //aqUtils.Delay(10000); colCount = Driver.ColumnCount;<-Fails at runtime, unless I'm debugging. while(!Driver. EOF()) { for(var i = 0; i < colCount - 1 ;i++) { Log.Message("Column " + i + " name is " + Driver.ColumnName(i) + " and it's value is " + Driver.Value(i)); } Driver.Next(); Log.Message("---------------------------- ROW --------------------------------------------") ; } }