我遇到了问题,如果"转换为字符串""输入'布尔'无效。"
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
答案 0 :(得分:-1)
多数民众赞成。
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