Forum Discussion

MichaelJohnson's avatar
MichaelJohnson
Regular Visitor
8 years ago

pass parameter in ado createrecordset

Hi there,

 

How do I pass a parameter in the ADO CreateRecordSet? Ie:

 

var userId = 1337;

 

qry.Open("SELECT COUNT(*) from [dbo].[Users] f WHERE f.UserId= userId", connectionString, -1, -1, adCmdText);

 

^^ UserId is being passed here.

 

1 Reply

  • NisHera's avatar
    NisHera
    Valued Contributor

    why do you need to pass anything for record-set?

    It's just a set of record you can not pass anything but read it.

     

    But if what you need is to put a where condition in query string you can do it  like this 

    var DBName = "database1";
    var UserID = "NewUser";
    var EmpNo = "0000123";
    
      qry = "select my_columnsA, my_columnsB FROM ["+DBName+"].[dbo].[My_Table] where USER_ID=";
      qry = qry+UserID+" AND EMPNO ="+EmpNo;

     note using same "qry" the query string, I can pass what ever i like to DBName, userID and  EmpNo

     

    you can get record set like this

            ADOCommand.CommandText = qry;
            RecSet = ADOCommand.Execute();