Forum Discussion

anatar02's avatar
anatar02
Contributor
13 years ago

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"]()



}




2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    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)