The scenario was there should be any or multiple TextBox that is not empty and display it on the DataGridView.

I think my SQL is incorrect.

 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

Recommended Answers

All 2 Replies

Shouldn't that be update Students i.o. Select * ?

if you are triing to select student that match the filters Get rid of the VALUES clause, put the txt?.Text values in the WHERE clause. Something like...
"WHERE ID = '" + txtID.Text + "' AND LastName = '" + txtLastN.Text & "' AND... Value

if you are triing to update the sutdent table change SELECT to UPDATE

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.