我有一个从vb应用程序正确运行的存储过程,我尝试使用vba Outlook功能执行相同的操作。当我尝试读取创建的记录的标识时,这会失败。 sp有以下回报 返回@@ IDENTITY 我使用记录集试图读取值,但这失败了。记录创建成功!我怎么会得到这个价值?
代码调用sp:
'创建记录时,命令参数和连接都正常!
Dim RS As ADODB.Recordset
Set RS = New ADODB.Recordset
RS.CursorType = adOpenStatic
RS.CursorLocation = adUseClient
RS.LockType = adLockOptimistic
'rs.Open cmd
Set RS = cmd.Execute
If Not RS Is Nothing Then
For Each fld In RS.Fields 'The fields are empty.
stMessage = stMessage & "| " & fld.Name & " / " & fld.Value & " |"
Next fld
End If
嗨工作代码如下:
Public Function AddNote(ByRef noteID As Integer, ByVal company As Int16, ByVal summary As String, ByVal notetxt As String,
ByVal NotesGroup As Integer, ByVal NotesType As Integer)
Try
Dim CN As New SqlConnection
CN.ConnectionString = My.Settings.TDb1
CN.Open()
Dim cmd As SqlCommand = New SqlCommand("AddImportedNotes", CN)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@CompanyId", company)
cmd.Parameters.AddWithValue("@User", 116)
cmd.Parameters.AddWithValue("@Summary", summary)
cmd.Parameters.AddWithValue("@Notes", notetxt)
cmd.Parameters.AddWithValue("@DateAdded", DateTime.Now)
cmd.Parameters.AddWithValue("@NotesType", NotesTypeId)
cmd.Parameters.AddWithValue("@Exported", 0)
cmd.Parameters.AddWithValue("@ExportFile", DBNull.Value)
cmd.Parameters.AddWithValue("@ExportDetails", DBNull.Value)
Dim prm As New SqlParameter("RETURN", SqlDbType.NVarChar)
' Dim recordId As Integer
cmd.Parameters.Add(prm)
prm.Direction = ParameterDirection.ReturnValue
cmd.ExecuteNonQuery()
noteID = CType(prm.Value, Integer)
CN.Close()
Return True
Catch ex As Exception
Return False
End Try