C# : 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 herehttps://bit.ly/2IJPxcm


🚀 4K UHD : Visual C# .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/686n651zAxc


🚀 Visual Basic .NET version: https://youtu.be/lP2R0sb4qDY


C# Source Code by iBasskung.


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;


namespace CSMDFDatabase

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void employeesBindingNavigatorSaveItem_Click(object sender, EventArgs e)

        {

            this.Validate();

            this.employeesBindingSource.EndEdit();

            this.tableAdapterManager.UpdateAll(this.myDatabaseDataSet);

        }


        private void Form1_Load(object sender, EventArgs e)

        {

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

            this.employeesTableAdapter.Fill(this.myDatabaseDataSet.Employees);

        }


        private void refreshToolStripButton_Click(object sender, EventArgs e)

        {

            refreshData();

        }


        private void refreshData()

        {

            // Clear filter.

            this.employeesBindingSource.Filter = null;


            this.employeesTableAdapter.Fill(this.myDatabaseDataSet.Employees);


            this.keywordToolStripTextBox.Text = "";

            this.keywordToolStripTextBox.Focus();


            this.addNewButton.Text = "Add new";

        }


        private void closeButton_Click(object sender, EventArgs e)

        {

            // Note: This is a comment.

            // Close this window.

            this.Close();

        }


        private void previousButton_Click(object sender, EventArgs e)

        {

            bindingNavigatorMovePreviousItem.PerformClick();

        }


        private void NextButton_Click(object sender, EventArgs e)

        {

            bindingNavigatorMoveNextItem.PerformClick();

        }


        private void addNewButton_Click(object sender, EventArgs e)

        {

            bindingNavigatorAddNewItem.PerformClick();

        }


        private void saveButton_Click(object sender, EventArgs e)

        {

            employeesBindingNavigatorSaveItem.PerformClick();

        }


        private void deleteButton_Click(object sender, EventArgs e)

        {

            bindingNavigatorDeleteItem.PerformClick();

        }


        private void employeesDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)

        {

            // Prevent the DataGridView Default Error.

            e.Cancel = true;

        }


        private void searchToolStripButton_Click(object sender, EventArgs e)

        {

            string strFilter = this.keywordToolStripTextBox.Text.Replace("'", "''");


            if (string.IsNullOrEmpty(this.keywordToolStripTextBox.Text))

            {

                refreshData();

            }

            else

            {


                string queryByID = "(Convert(EmployeeID, 'System.String') = '" + strFilter.Trim() + "') ";


                string queryByName = "OR (EmployeeName LIKE '%" + strFilter + "%') "; // % Wildcard


                string queryByPhone = "OR (MobilePhone LIKE '%" + strFilter + "%') ";


                string queryByPage = "OR (FacebookPage LIKE '%" + strFilter + "%') ";


                string queryByAddress = "OR (Address LIKE '%" + strFilter + "%')";


                StringBuilder joinQuery = new StringBuilder(); // System.Text


                joinQuery.Append(queryByID);

                joinQuery.Append(queryByName);

                joinQuery.Append(queryByPhone);

                joinQuery.Append(queryByPage);

                joinQuery.Append(queryByAddress);


                this.employeesBindingSource.Filter = joinQuery.ToString();


            }

        }


    }

}


📚 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! 💯

#CSharp #VisualCSharp #FreeSourceCode #MDF #SQLServer #PointOfSale #POS #VisualStudio  

Comments