VBScript To VB.NET Recodset question.

R

Ron Pagliuca

I am trying to execute VBScript functions via MSScriptControl in
VB.NET and have the function return a ADODB Recordset. rs3 in the
example below is returned as type __ComObject. I tried using
Marshal.CreateWrapperTypeOf to create a COM wrapper. Anyone have any
ideas how I can I access the recordset back in vb.net, I am able to
get a fields value back from the function. I am interested in using
the RS -- Such As: Dim rs as new ADODB.Recordset = rs3 .

Thanks
Ron

----- Code Snippet ------
Dim sc As New MSScriptControl.ScriptControl()
sc.Language = "VBScript"
sc.AddCode("Function xcv()" & vbCrLf & "SET db =
CreateObject(""ADODB.Connection"")" & vbCrLf &
"db.Open(""PROVIDER=SQLOLEDB;UID=psafe_user;PWD=psafe_user;SERVER=IKE;DATABASE=psafe2;"")"
& vbCrLf & "set rs2 = db.execute(""select * from issue"")" & vbCrLf &
"xcv=rs2" & vbCrLf & "End Function")

Dim ex As String = "xcv"
Dim rs3 As New Object()

rs3 = sc.Eval(ex)
 
A

Armin Zingler

Ron Pagliuca said:
I am trying to execute VBScript functions via MSScriptControl in
VB.NET and have the function return a ADODB Recordset. rs3 in the
example below is returned as type __ComObject. I tried using
Marshal.CreateWrapperTypeOf to create a COM wrapper. Anyone have
any ideas how I can I access the recordset back in vb.net, I am able
to get a fields value back from the function. I am interested in
using the RS -- Such As: Dim rs as new ADODB.Recordset = rs3 .

Thanks
Ron

----- Code Snippet ------
Dim sc As New MSScriptControl.ScriptControl()
sc.Language = "VBScript"
sc.AddCode("Function xcv()" & vbCrLf & "SET db =
CreateObject(""ADODB.Connection"")" & vbCrLf &
"db.Open(""PROVIDER=SQLOLEDB;UID=psafe_user;PWD=psafe_user;SERVER=IKE;DATABA
SE=psafe2;"")"
& vbCrLf & "set rs2 = db.execute(""select * from issue"")" & vbCrLf
& "xcv=rs2" & vbCrLf & "End Function")

Dim ex As String = "xcv"
Dim rs3 As New Object()

rs3 = sc.Eval(ex)


After setting a reference to the ADODB COM library, does

Dim rs as ADODB.Recordset
rs = directcast(rs3, adodb.recordset)

work?
 
R

Ron Pagliuca

I am not sure if my reply posted as I do not see it anywhere. DIRECT
CAST did not work, it gave a "SPECIFIED CAST NOT VALID". I did make the
ADODB COM reference as well then executed my code. Any further
assistance would be welcomed... Oh dire straits...

Thanks Again,

Ron
 
R

Ron Pagliuca

DIRECTCAST did not work error message is "SPECIFIED CAST IS NOT VALID".
I also tried CTYPE similar results too. Any other suggestions would be
helpful. The VBscript is executing, because I can return a STRING from
it. I have a COM reference in VS.NET in my VB.NET project to ADODB as
well. Please help me out, I truly appreciate it.

Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top