VBScript To VB.NET Recodset question.

  • Thread starter Thread starter Ron Pagliuca
  • Start date Start date
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)
 
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?
 
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
 
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
 
Back
Top