"Conversion from string "“键入 'Boolean' 无效。”
"Conversion from string "" to type 'Boolean' is not valid."
如果 "Conversion from string "" 键入 'Boolean' 无效,我会遇到问题。"
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
这就是答案。
Private Sub xls_opn(sender As Object, e As EventArgs) 句柄 openxls.Click
Dim cmdselcet = New OleDbCommand
Dim adapter As New OleDbDataAdapter
Using cn As New OleDbConnection(constr)
Try
cn.Open()
'1 üres,üres,üres
If xlstxtbox1.Text.Length = 0 & xlstxtbox2.Text.Length = 0 & xlstxtbox3.Text.Length = 0 Then
cmdselcet = New OleDbCommand("select * from [sheet1$]", cn)
'2 nem,üres,üres
ElseIf xlstxtbox1.Text.Length <> 0 & xlstxtbox2.Text.Length = 0 & xlstxtbox3.Text.Length = 0 Then
cmdselcet = New OleDbCommand("select " + xlstxtbox1.Text + " from [sheet1$] ", cn)
'3 üres,nem,üres
ElseIf xlstxtbox1.Text.Length = 0 & xlstxtbox2.Text.Length <> 0 & xlstxtbox3.Text.Length = 0 Then
cmdselcet = New OleDbCommand("select * from [" + xlstxtbox2.Text + "$] ", cn)
'4 üres,üres,nem
ElseIf xlstxtbox1.Text.Length = 0 & xlstxtbox2.Text.Length = 0 & xlstxtbox3.Text.Length <> 0 Then
cmdselcet = New OleDbCommand("select * from [sheet1$] " + xlstxtbox3.Text, cn)
'5 nem,nem,üres
ElseIf xlstxtbox1.Text.Length <> 0 & xlstxtbox2.Text.Length <> 0 & xlstxtbox3.Text.Length = 0 Then
cmdselcet = New OleDbCommand("select " + xlstxtbox1.Text + " from [" + xlstxtbox2.Text + "$] ", cn)
'6 üres,nem,nem
ElseIf xlstxtbox1.Text.Length = 0 & xlstxtbox2.Text.Length <> 0 & xlstxtbox3.Text.Length <> 0 Then
cmdselcet = New OleDbCommand("select * from [" + xlstxtbox2.Text + "$] " + xlstxtbox3.Text, cn)
'7 nem,üres,nem
ElseIf xlstxtbox1.Text.Length <> 0 & xlstxtbox2.Text.Length = 0 & xlstxtbox3.Text.Length <> 0 Then
cmdselcet = New OleDbCommand("select " + xlstxtbox1.Text + " from [sheet1$] " + xlstxtbox3.Text, cn)
'8 nem,nem,nem
ElseIf xlstxtbox1.Text.Length <> 0 & xlstxtbox2.Text.Length <> 0 & xlstxtbox3.Text.Length <> 0 Then
cmdselcet = New OleDbCommand("select " + xlstxtbox1.Text + " from [" + xlstxtbox2.Text + "$] " + xlstxtbox3.Text, cn)
End If
adapter.SelectCommand = cmdselcet
Dim ds As DataSet
ds = New DataSet
'Megjelenítés
adapter.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
DataGridView1.Visible = True
MsgBox("XLS/XLSX import kész!")
Catch ex As Exception
DataGridView1.Visible = False
MsgBox(ex.Message)
End Try
End Using
End Sub
如果 "Conversion from string "" 键入 'Boolean' 无效,我会遇到问题。"
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
这就是答案。
Private Sub xls_opn(sender As Object, e As EventArgs) 句柄 openxls.Click
Dim cmdselcet = New OleDbCommand
Dim adapter As New OleDbDataAdapter
Using cn As New OleDbConnection(constr)
Try
cn.Open()
'1 üres,üres,üres
If xlstxtbox1.Text.Length = 0 & xlstxtbox2.Text.Length = 0 & xlstxtbox3.Text.Length = 0 Then
cmdselcet = New OleDbCommand("select * from [sheet1$]", cn)
'2 nem,üres,üres
ElseIf xlstxtbox1.Text.Length <> 0 & xlstxtbox2.Text.Length = 0 & xlstxtbox3.Text.Length = 0 Then
cmdselcet = New OleDbCommand("select " + xlstxtbox1.Text + " from [sheet1$] ", cn)
'3 üres,nem,üres
ElseIf xlstxtbox1.Text.Length = 0 & xlstxtbox2.Text.Length <> 0 & xlstxtbox3.Text.Length = 0 Then
cmdselcet = New OleDbCommand("select * from [" + xlstxtbox2.Text + "$] ", cn)
'4 üres,üres,nem
ElseIf xlstxtbox1.Text.Length = 0 & xlstxtbox2.Text.Length = 0 & xlstxtbox3.Text.Length <> 0 Then
cmdselcet = New OleDbCommand("select * from [sheet1$] " + xlstxtbox3.Text, cn)
'5 nem,nem,üres
ElseIf xlstxtbox1.Text.Length <> 0 & xlstxtbox2.Text.Length <> 0 & xlstxtbox3.Text.Length = 0 Then
cmdselcet = New OleDbCommand("select " + xlstxtbox1.Text + " from [" + xlstxtbox2.Text + "$] ", cn)
'6 üres,nem,nem
ElseIf xlstxtbox1.Text.Length = 0 & xlstxtbox2.Text.Length <> 0 & xlstxtbox3.Text.Length <> 0 Then
cmdselcet = New OleDbCommand("select * from [" + xlstxtbox2.Text + "$] " + xlstxtbox3.Text, cn)
'7 nem,üres,nem
ElseIf xlstxtbox1.Text.Length <> 0 & xlstxtbox2.Text.Length = 0 & xlstxtbox3.Text.Length <> 0 Then
cmdselcet = New OleDbCommand("select " + xlstxtbox1.Text + " from [sheet1$] " + xlstxtbox3.Text, cn)
'8 nem,nem,nem
ElseIf xlstxtbox1.Text.Length <> 0 & xlstxtbox2.Text.Length <> 0 & xlstxtbox3.Text.Length <> 0 Then
cmdselcet = New OleDbCommand("select " + xlstxtbox1.Text + " from [" + xlstxtbox2.Text + "$] " + xlstxtbox3.Text, cn)
End If
adapter.SelectCommand = cmdselcet
Dim ds As DataSet
ds = New DataSet
'Megjelenítés
adapter.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
DataGridView1.Visible = True
MsgBox("XLS/XLSX import kész!")
Catch ex As Exception
DataGridView1.Visible = False
MsgBox(ex.Message)
End Try
End Using
End Sub