• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to catch the result in a variable?

ravikumar00008

New Member
Hi All,


I want to catch the ID comming from the sqlTable like this but i am not succeeded


~

ColA = shtSheetToWork.Cells(lRow, 1)

ColB = shtSheetToWork.Cells(lRow, 2)

SplitMonth="Jun"

SplitYear="2012"

SQLSelect = "select ID from Test where Country= ' " & ColA & " ' and Name=' " & ColB & " ' and Month=' " & SplitMonth& " ' and Year=' " & SplitYear & " ' "

Cn.Execute SQLSelect


~

Here how can i catch the result in a variable.


Please help me to achieve this.


Regards

Kumar
 
Hello Ravikumar,


Make use of the RecordSet Object here.


Instead of directly executing your SQL statement by calling Cn.Execute.


Open a RecordSet and pass the SQL as the Source.


Dim rs as New ADODB.RecordSet -If you can afford Early Binding

Dim rs as Adodb.RecordSet - If late binding will work for you


In late binding case

Set Rs = New ADODB.RecordSet


Rs.Open SQLSelect,Cn


Now you can read the record from your recordset and store it into a variable.


If you need more help let us know.


~VijaySharma
 
Back
Top