English 中文(简体)
VB6:这个tsql过程调用有什么问题?
原标题:VB6: what s wrong with this tsql procedure call?
  • 时间:2010-10-18 00:50:38
  •  标签:
  • vb6
  • ado

我在VB6中有以下过程调用:

dim rs as adodb.command 
dim cnn as adodb.connection 

with rs
    set .activeconnection = cnn 
    .CommandType = adCmdStoredProc 
    .CommandText = "sp_qryUpdate" 
    .CommandTimeout = 0 
    .Parameters("@uidbatch").value = lngBatchID 
    .Execute , , adExecuteNoRecords 
end with 

我收到的错误是,

对象变量或未设置块变量

设置.activeconnection后抛出错误

你知道这意味着什么吗?我收到的连接字符串是正确的。

最佳回答

奇怪的是,rs通常用于指示一个记录集,而不是一个命令,但我想每个记录集都有自己的命令。

我看到了一些潜在的问题。我不完全确定其中的区别,因为我接触VB6的时间很短,但我所做的所有代码都有:

dim rs as new adodb.recordset

在其中(即使用new关键字)。这可能会造成问题。

我还假设您在第二个dim和带有的之间有一些代码,是吗?

因为除此之外,您实际上并没有打开连接以供使用。

有一些教程代码这里这可能会有所帮助。我会说“享受吧!“但我不认为这是一个选择:-)

问题回答

在使用之前,必须创建adodb.commandadodb.connection的实例。

试试这个

dim rs as New adodb.command 
dim cnn as New adodb.connection 

正如其他人所说,您需要创建rs和cnn,但也需要向参数集合添加一个新参数。

.Parameters("@uidbatch").value

这是假设它已经存在。

您可以进行所有手动参数定义,但只使用rs.Parameters.Refresh要容易得多。这将自动正确填充参数集合。

此外,虽然必须实例化对象变量是正确的,但不建议在同一行执行。与.Net不同,这实际上并没有实例化变量。相反,每次引用变量时,运行时都会检查是否存在实例,如果不存在,则会创建一个实例。这会产生不必要的开销。最佳做法是在新行中使用Set关键字。





相关问题
Prevent windows from queuing shellexecute requests

Win.ShellExecute 0, "open", "C:dirprogram.exe", "arguments", vbNullString, SW_SHOWNORMAL Win.ShellExecute 0, "open", "http://www.google.com", vbNullString, vbNullString, SW_SHOWNORMAL I want google....

Why is My Loop Only Deleting One File?

Using VB6 In a folder, i have n number of files, i want to delete a 0 kb files code Dim filename5 As String filename5 = Dir$(txtsourcedatabasefile & "*_*", vbDirectory) MsgBox filename5 Do ...

How to check the filesize?

Using VB6 I have the text file with different sizes, so i want to delete the file where filesize = 0 kb. How to make a vb6 code for deleting the 0 kb files. Need vb6 code Help

File Rename problem?

I m using VB6 and I have a folder where I have n number of files. I want to change the file extension to .txt. I used the code below to change the extension of all .fin files to .txt. Dim filename1 ...

Error 20728-F while in using Crystal Reports in VB6

I m using Crystal Reports in my VB6 project, but I m facing error while loading the report in crystalreport1.action=1; Please give me some solution for this problem. It is showing the error as Error ...

DllRegisterServer entry point was not found

When running my vb6 application I am getting error like, runtime error 53 : file not found: rscomclNoMsg.dll then i tried to register that dll from cmd line using regsvr32. Then I am getting ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8