Ask a Question

Unable to fetching data from SQL server by using C#

anatar02
Contributor

Unable to fetching data from SQL server by using C#

Hi All,



I have written the set of below code to fectching the data from sql server by using C#. Its executed successfully without any error but unfortunately  its not fetching any data from db.

Some one please have a look and let me know that where i am missing.







function doGetTestSuiteRunId()

{

 var mConnection, RecSet, Cmd, sql,Prm;



 mConnection=Sys["OleObject"]("ADODB.Connection");

 mConnection["Open"]("Driver={SQL Native Client};"+"Server=BLRWIN7VM01;"+"Database=execution_log;"+ "Uid=sa;"+"Pwd=test");

 

 Prm=mConnection["Execute"]("SELECT top 1 TestSuiteRunId FROM TestSuiteRunId where data='test' ORDER BY TestSuiteRunId DESC");

 Log["Message"](Prm)



mConnection["Close"]()



}




Thanks
Ashok N
2 REPLIES 2
tristaanogre
Community Hero

RE: Unable to fetching data from SQL server by using C#

The execute call returns a RecordSet object which is a list of records in a particular format for you to be able to traverse and pull out specific values.  So, when you are calling Log.Message(PRM), you're trying to log as a string an object that does not convert to a string.



I don't know C# syntax very well so excuse any syntax errors.  But if you want the value returned from your query, you should call something on the lines of 



Log["Message"](Prm.Fields(0).Value)




Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
anatar02
Contributor

RE: Unable to fetching data from SQL server by using C#

Thanks, it works
Thanks
Ashok N
cancel
Showing results for 
Search instead for 
Did you mean: