excel - 变量在没有被告知的情况下表示开头的引用
问题描述
我试图从 SQL 中提取一个显示“收件箱”的值。
Function MailboxInbox(ActiveEmail As String, ActiveEmailInbox As String, ValidMailbox, conn As ADODB.Connection, rs As ADODB.Recordset, sConnString As String)
Call OpenSQLCon.ConnectSqlServer(conn, rs, sConnString)
Dim SQL As String
SQL = "Select distinct coalesce(Mailbox_1,Mailbox_2,Mailbox_3) from [MAP].[Config].[TB_SU_MAP_Mailbox_Configuration] where Mailbox_Name ='" & ActiveEmail & "'"
Debug.Print SQL
' Open the connection and execute.
conn.Open sConnString
Set rs = conn.Execute(SQL)
If rs.EOF = True Or rs.BOF = True Then
ValidMailbox = 1
Exit Function
Else
ActiveEmailInbox = rs(0)
Debug.Print ActiveEmailInbox
End If
'Close SQL
Call CloseSQLCon.CSC(conn, rs, sConnString)
End Function
我正在连接到 SQL 服务器,发送查询并拉回我放入记录集中的单个值。在 SQL 表中,值为 Inbox,五个字符,没有"。
但是,当我使用记录集中的值填充变量“ActiveEmailInbox”时,它将其设置为“收件箱
当我稍后在代码中使用此值时,我无法将邮箱设置为“收件箱”,因为它设置为“收件箱”。当我将值 ActiveEmailInbox 打印到调试窗口时,它显示为收件箱。
带有变量的代码设置为“收件箱”
打印到调试窗口的变量值,显示时没有“
解决方案
虽然这可能是解决症状而不是实际问题,但您可以尝试在返回字符串时从字符串中删除第一个字符,这意味着 " 被删除。
ActiveEmailInbox = Right(ActiveEmailInbox , Len(ActiveEmailInbox) - 1)
推荐阅读
- mysql - SQL日期间隔不适用于AND子句
- c# - 如果 int 值等于 x 替换为字符串
- android - Putting ImageView in front of other elements < 21API
- reactjs - How to correctly validate an masked-input using material-ui, formik, yup, and react-input-mask?
- java - 编译错误将实例方法声明为静态上下文(Java 6)
- jenkins - Jenkins: C:Program No such file or directory
- python-3.x - output.write(bytearray(image[y][x])) TypeError: write() 参数必须是 str,而不是 bytearray
- apache-spark - Apache Spark 无法反序列化集群上的“TopicPartition”
- iis - 在 IIS 下服务的 Vue.js 无法找到资产文件
- .net-core - .NET Core 3 是否与 Windows 7 兼容?