該場景是應該有任何或多個TextBox
不是空的並將其顯示在DataGridView
上。使用任何已輸入的文本框過濾DataGrid
我認爲我的SQL不正確。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Command1 As New OleDbCommand
Dim i2 As Integer
Dim sql1 As String
Try
Dim cnn3 = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=StudentInfoSysDB.accdb;")
cnn3.Open()
If txtID.Text <> "" OrElse txtLastN.Text <> "" OrElse txtFirstN.Text <> "" OrElse txtMiddleN.Text <> "" OrElse txtCourse.Text <> "" OrElse txtYear.Text <> "" OrElse txtGender.Text <> "" OrElse txtSection.Text <> "" Then
sql1 = "Select * from Students Where([ID],[LastName],[FirstName],[MiddleName],[Course],[Year],[Gender],[Section]) VALUES('" & txtID.Text & "','" & txtLastN.Text & "','" & txtFirstN.Text & "','" & txtMiddleN.Text & "','" & txtCourse.Text & "','" & txtYear.Text & "','" & txtGender.Text & "','" & txtSection.Text & "')"
Command1 = New OleDbCommand(sql1, cnn3)
i2 = Command1.ExecuteNonQuery
MessageBox.Show("Searching Done!")
ds.Clear()
Refresh()
cnn3.Close()
Else
MsgBox("Please Input Atleast 1 Field")
End If
Catch ex As Exception
End Try
End Sub
請不要用基於答案的新問題替換原來的問題。通過添加更新來編輯問題,或在回答 – equisde