【发布时间】:2015-01-19 08:00:05
【问题描述】:
如果“从字符串”转换为类型“布尔”无效,我会遇到问题。”
If xlstxtbox1.Text = "" & xlstxtbox2.Text = "" & xlstxtbox3.Text = "" Then
cmdselcet = New OleDbCommand("select * from [sheet1$]",cn)
'2
ElseIf xlstxtbox1.Text <> "" & xlstxtbox2.Text = "" & xlstxtbox3.Text = "" Then
cmdselcet = New OleDbCommand("select " + xlstxtbox1.Text + "from [sheet1$] ", cn)
'3
ElseIf xlstxtbox1.Text = "" & xlstxtbox2.Text <> "" & xlstxtbox3.Text = "" Then
cmdselcet = New OleDbCommand("select * from [" + xlstxtbox2.Text + "$] ", cn)
'4
ElseIf xlstxtbox1.Text = "" & xlstxtbox2.Text = "" & xlstxtbox3.Text <> "" Then
cmdselcet = New OleDbCommand("select * from [sheet1$] " + xlstxtbox3.Text, cn)
'5
ElseIf xlstxtbox1.Text <> "" & xlstxtbox2.Text <> "" & xlstxtbox3.Text = "" Then
cmdselcet = New OleDbCommand("select " + xlstxtbox1.Text + "from [" + xlstxtbox2.Text + "$] ", cn)
'6
ElseIf xlstxtbox1.Text = "" & xlstxtbox2.Text <> "" & xlstxtbox3.Text <> "" Then
cmdselcet = New OleDbCommand("select * from [" + xlstxtbox2.Text + "$] " + xlstxtbox3.Text, cn)
'7
ElseIf xlstxtbox1.Text <> "" & xlstxtbox2.Text = "" & xlstxtbox3.Text <> "" Then
cmdselcet = New OleDbCommand("select " + xlstxtbox1.Text + " from [sheet1$] " + xlstxtbox3.Text, cn)
'8
ElseIf xlstxtbox1.Text <> "" & xlstxtbox2.Text <> "" & xlstxtbox3.Text <> "" Then
cmdselcet = New OleDbCommand("select " + xlstxtbox1.Text + " from [" + xlstxtbox2.Text + "$] " + xlstxtbox3.Text, cn)
End If
【问题讨论】:
-
您为什么希望能够将空字符串转换为布尔值?也许你可以找出哪个表达式产生了错误。
-
这是我的选择,但我的例外是此消息:“从字符串“”转换为“布尔”类型无效。”我刚刚写了这个问题,但它被删除了。我只是想得到一个答案,我该如何解决它。
-
首先找出代码中您尝试将空字符串转换为布尔值的位置。这是在代码中的什么地方发生的?
-
nwm,抱歉耽误你的时间,我找到了这样的方法:xlstxtbox1.Text.length = 0
-
我在问题中看不到该代码。这非常令人困惑。
标签: vba type-conversion