VB.NET : The Easy Way : Search Data in SQL Server Database File (.mdf) using BindingSource Filter



👨‍🏫 Please watch the top 3 most popular videos on my channel.

🥇 33 Million Views : Programming in Visual Basic .Net How to Connect Access Database to VB.NET : https://youtu.be/cwDqjmSmtMQ

🥈 13 Million Views : Visual Basic .Net : Search in Access Database - DataGridView BindingSource Filter (Part 1/2) : https://youtu.be/UoT2oava9ns

🥉 2 Million Views : Visual Basic .Net : Search in Access Database - DataGridView BindingSource Filter (Part 2/2) : https://youtu.be/e5Dvkw7moWg

💰 Donate $29 USD and Receive a free PDF Source Code of the above project:
https://www.paypal.com/paypalme/CodeAMinute/29USD
📧 Contact the instructor via this email: ibasskung@gmail.com

✔ This project is also included: (Export Data To Excel): https://youtu.be/whwQWX4sR7Y

💡 Premium Online Courses 💡

🎓 Master Visual Basic .NET and Access Database By Building the Point Of Sale System (POS)
📲 Enroll Now: https://bit.ly/2WcbRhX

🎓 Learn C# and SQL Server 2019 by Building Windows Forms Application with ADO.NET
📲 Enroll Now: https://bit.ly/37iLrRX

📚 See all courses here: https://bit.ly/2IJPxcm


🚀 4K UHD : Visual Basic .NET Project : The Easy Way! - How to Search Data in SQL Server Database File (.mdf) using BindingSource Filter in Visual Studio 2019.
🎦 Watch in 4K on YouTube: https://youtu.be/lP2R0sb4qDY


🚀 Visual C# .NET version: https://youtu.be/686n651zAxc


VB.NET Source Code by iBasskung.


Public Class Form1

Private Sub CustomersBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles CustomersBindingNavigatorSaveItem.Click

        Me.Validate()

        Me.CustomersBindingSource.EndEdit()

        Me.TableAdapterManager.UpdateAll(Me.YourDatabaseDataSet)

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        'TODO: This line of code loads data into the 'YourDatabaseDataSet.Customers' table. You can move, or remove it, as needed.

        Me.CustomersTableAdapter.Fill(Me.YourDatabaseDataSet.Customers)

End Sub

Private Sub RefreshToolStripButton_Click(sender As Object, e As EventArgs) Handles RefreshToolStripButton.Click

        ' Call Sub-procedure.

        RefreshData()

End Sub

Private Sub RefreshData()

        ' Clear filter.

        Me.CustomersBindingSource.Filter = Nothing

        Me.CustomersTableAdapter.Fill(Me.YourDatabaseDataSet.Customers)

        With KeywordToolStripTextBox

            .Text = ""

            .Focus()

        End With

        AddNewButton.Text = "Add new"

End Sub

Private Sub CloseButton_Click(sender As Object, e As EventArgs) Handles CloseButton.Click

        ' Note: This is a comment.

        ' Close this window.

        Me.Close()

End Sub

Private Sub PreviousButton_Click(sender As Object, e As EventArgs) Handles PreviousButton.Click

        BindingNavigatorMovePreviousItem.PerformClick()

End Sub

Private Sub NextButton_Click(sender As Object, e As EventArgs) Handles NextButton.Click

        BindingNavigatorMoveNextItem.PerformClick()

End Sub

Private Sub AddNewButton_Click(sender As Object, e As EventArgs) Handles AddNewButton.Click

        BindingNavigatorAddNewItem.PerformClick()

End Sub

Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click

        CustomersBindingNavigatorSaveItem.PerformClick()

End Sub

Private Sub DeleteButton_Click(sender As Object, e As EventArgs) Handles DeleteButton.Click

        BindingNavigatorDeleteItem.PerformClick()

End Sub

Private Sub SearchToolStripButton_Click(sender As Object, e As EventArgs) Handles SearchToolStripButton.Click


        Dim strFilter As String = Me.KeywordToolStripTextBox.Text.Replace("'", "''")


        If String.IsNullOrEmpty(Me.KeywordToolStripTextBox.Text) Then

            RefreshData()

        Else


            Dim queryByID As String = "(Convert(CustomerID, 'System.String') = '" & strFilter & "') "


            Dim queryByName As String = "OR (CustomerName LIKE '%" & strFilter & "%') "


            Dim queryByPhone As String = "OR (MobilePhone LIKE '%" & strFilter & "%') "


            Dim queryByPage As String = "OR (FacebookPage LIKE '%" & strFilter & "%') "


            Dim queryByAddress As String = "OR (Address LIKE '%" & strFilter & "%')"


            Dim joinQuery As New System.Text.StringBuilder()


            joinQuery.Append(queryByID)

            joinQuery.Append(queryByName)

            joinQuery.Append(queryByPhone)

            joinQuery.Append(queryByPage)

            joinQuery.Append(queryByAddress)


            Me.CustomersBindingSource.Filter = joinQuery.ToString()


        End If


End Sub

Private Sub CustomersDataGridView_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles CustomersDataGridView.DataError

        ' Prevent the DataGridView Default Error.

        e.Cancel = True

End Sub

End Class


📚 See all courses here: https://www.udemy.com/user/tanin-sangngam


Follow me around

✔ Want to get updates on new courses or other cool free stuff? Just follow me on social media if that's your thing!

📺 Pages:
📍 https://www.facebook.com/CodeAMinute
📍 https://www.facebook.com/IbasskungTutorial
📍 https://www.facebook.com/codewithibasskung
📍 https://www.facebook.com/iBasskungAcademy

📺 YouTube:
📍 https://www.youtube.com/c/iBasskung

📺 Udemy:
📍 https://www.udemy.com/user/tanin-sangngam

📺 Twitter:
📍 https://twitter.com/IBasskung

📺 Pinterest:
📍 https://www.pinterest.com/ibasskung

📺 Blogger:
📍 .NET: https://codeaminute.blogspot.com
📍 JAVA: https://javacodeminutes.blogspot.com
📍 VBA: https://vbacodeminutes.blogspot.com

💯 THANK YOU SO MUCH! 💯

#VB #VisualBasic #FreeSourceCode #MDF #SQLServer #PointOfSale #POS #VisualStudio  

Comments