C# Code - How To Filter Data In MySQL And Show It On DataGridView Using C#
__________________________________________________________________________
In This C# Tutorial We Will Learn How To Find Data In MySQL Database With A
Specific Value From TextBox And Display The Result In DataGridView Using CSharp
Programming Language .
*Java Courses : Java Complete Course
Java Swing Course
In This C# Tutorial We Will Learn How To Find Data In MySQL Database With A
Specific Value From TextBox And Display The Result In DataGridView Using CSharp
Programming Language .
*Java Courses : Java Complete Course
Java Swing Course
Project Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace WindowsFormsApplication1
{
public partial class Csharp_Datagridview_Data_Search : Form
{
public Csharp_Datagridview_Data_Search()
{
InitializeComponent();
}
MySqlConnection con = new MySqlConnection("datasource = localhost;port = 3306; Initial Catalog = 'test_db'; username = root; password=");
MySqlCommand command;
MySqlDataAdapter adapter;
DataTable table;
private void Csharp_Datagridview_Data_Search_Load(object sender, EventArgs e)
{
searchData("");
}
public void searchData(string valueToSearch)
{
string searchQuery = "SELECT * FROM `users` WHERE CONCAT(`id`, `fname`, `lname`, `age`) LIKE '%" + valueToSearch + "%'";
command = new MySqlCommand(searchQuery, con);
adapter = new MySqlDataAdapter(command);
table = new DataTable();
adapter.Fill(table);
dataGridView1.DataSource = table;
}
private void button_search_Click(object sender, EventArgs e)
{
string valueToSearch = textBox_Value.Text.ToString();
searchData(valueToSearch);
}
}
}
Bagikan
C# And MySQL - How To Search Data In MySQL And Display It On DataGridView Using C#
4/
5
Oleh
insurance