Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

--errorurgent help

i am getting in the bold line and the error is "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another."
how can i resolve this
trQry = "Select * from OPTIMIZER"
'Connection String
strConnection = ("provider=sqloledb;Server=VSDOMAIN;database=IDCExtract;Uid=sa;")
Dim cnAp As OleDb.OleDbConnection
cnAp = New OleDb.OleDbConnection(strConnection)
cnAp.Open()
If cnAp.State = ConnectionState.Open Then
MsgBox("Connection is open")
ElseIf cnAp.State = ConnectionState.Closed Then
MsgBox("Connection is colsed")
End If
rs = New ADODB.Recordset
rs.Open(strQry, cnAp, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
iFreeFile = FreeFile()
file_name = "c:\abc1.txt"
FileOpen(iFreeFile, file_name, OpenMode.Append)

For i = 0 To rs.Fields.Count - 1
Print(iFreeFile, rs.Fields(i).Name & ";")
Next
Print(iFreeFile, "")

For i = 0 To rs.RecordCount - 1
For j = 0 To rs.Fields.Count - 1
Print(iFreeFile, rs.Fields(j).Value & ",")
Next
Print(iFreeFile, "")
rs.MoveNext()
Next
' Close(iFreeFile)
rs.Clone()
rs = Nothing
cnAp.Close()
[1507 byte] By [him_mca] at [2007-11-11 10:12:44]
# 1 Re: --errorurgent help
Any time you assign a variable using the "New" keyword, you must also use "Set." So you need to change these two lines:

cnAp = New OleDb.OleDbConnection(strConnection)
rs = New ADODB.Recordset

to this:

Set cnAp = New OleDb.OleDbConnection(strConnection)
Set rs = New ADODB.Recordset

See if that helps.
Phil Weber at 2007-11-11 17:22:57 >
# 2 Re: --errorurgent help
Any time you assign a variable using the "New" keyword, you must also use "Set." So you need to change these two lines:

cnAp = New OleDb.OleDbConnection(strConnection)
rs = New ADODB.Recordset

to this:

Set cnAp = New OleDb.OleDbConnection(strConnection)
Set rs = New ADODB.Recordset

See if that helps.
hi it does'nt work for vb.net
i am using vb.net
him_mca at 2007-11-11 17:23:58 >
# 3 Re: --errorurgent help
and here is vb classic so u must put your code in .net section ;)
Amahdy at 2007-11-11 17:25:04 >
# 4 Re: --errorurgent help
how can i resolve this
trQry = "Select * from OPTIMIZER"
...
rs.Open(strQry, cnAp, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic

Phil is of course correct about missing the Set for your object assignments at least for VB6; but I also noticed that if this code is exactly what is in your program then you have also mistyped the variable name for the select statement. It should be strQry not trQry
Ron Weller at 2007-11-11 17:26:00 >