Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to Auto Search Data From Database in C# .Net
WhatsApp
Pintoo Yadav
Jan 07
2015
3.4
k
0
0
AutoSearch.rar
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
System.Data.OleDb;
namespace
ClientManagementApp
{
public
partial
class
SearchClient : Form
{
DataSet dstResults =
new
DataSet();
DataView myView;
public
SearchClient()
{
InitializeComponent();
}
public
static
OleDbConnection conection()
{
OleDbConnection con =
new
OleDbConnection(
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=ClientMgmtDb.accdb;"
);
if
(con.State == ConnectionState.Closed)
con.Open();
return
con;
}
private
void
txtSearch_KeyUp(
object
sender, KeyEventArgs e)
{
string
outputInfo =
""
;
string
[] keyWords = txtSearch.Text.Split(
' '
);
foreach
(
string
word
in
keyWords)
{
if
(outputInfo.Length == 0)
{
outputInfo =
"(BankName LIKE '%"
+ word +
"%' OR ContactPersonName LIKE '%"
+
word +
"%' OR ContactNumber LIKE '%"
+ word +
"%')"
;
}
else
{
outputInfo +=
" AND (BankName LIKE '%"
+ word +
"%' OR ContactPersonName LIKE '%"
+
word +
"%' OR ContactNumber LIKE '%"
+ word +
"%')"
;
}
}
myView.RowFilter = outputInfo;
}
private
void
SearchClient_Load(
object
sender, EventArgs e)
{
////OleDbConnection con = conection();
////OleDbCommand cmd;
//////DataSet ds=new DataSet();
////DataTable ds = new DataTable();
////string str = "select * from tbl_ClientDetails";
////cmd = new OleDbCommand(str, con);
////OleDbDataAdapter da = new OleDbDataAdapter(cmd);
//////da.Fill(ds, "default");
////da.Fill(ds);
////dataGridView1.DataSource = ds;
////con.Close();
ReadData(
"SELECT * FROM tbl_ClientDetails"
,
ref
dstResults,
"BankName"
);
myView = ((DataTable)dstResults.Tables[
"BankName"
]).DefaultView;
dataGridView1.DataSource = myView;
}
public
void
ReadData(
string
strSQL,
ref
DataSet dstMain,
string
strTableName =
"default"
)
{
try
{
string
connectionString = @
" Provider=Microsoft.ACE.OLEDB.12.0;Data Source=ClientMgmtDb.accdb;"
;
// OleDbConnection cnn = conection();
OleDbConnection cnn =
new
OleDbConnection(connectionString);
OleDbCommand cmd =
new
OleDbCommand(strSQL, cnn);
cnn.Open();
OleDbDataAdapter da =
new
OleDbDataAdapter(cmd);
da.Fill(dstMain, strTableName);
da.Dispose();
cnn.Close();
}
catch
(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
private
void
txtSearch_TextChanged(
object
sender, EventArgs e)
{
txtSearch.BackColor = System.Drawing.Color.Yellow;
}
private
void
dt_PaymentRecvdDate_KeyUp(
object
sender, KeyEventArgs e)
{
string
outputInfo =
""
;
string
[] keyWords = dt_PaymentRecvdDate.Text.Split(
' '
);
foreach
(
string
word
in
keyWords)
{
if
(outputInfo.Length == 0)
{
outputInfo =
"(PayementRecievedDate LIKE '%"
+ word +
"%' OR ContactPersonName LIKE '%"
+
word +
"%' OR InstalledDate LIKE '%"
+ word +
"%')"
;
}
else
{
outputInfo +=
" AND (PayementRecievedDate LIKE '%"
+ word +
"%' OR ContactPersonName LIKE '%"
+
word +
"%' OR InstalledDate LIKE '%"
+ word +
"%')"
;
}
}
myView.RowFilter = outputInfo;
}
}
}
C#
Auto Search Data
Database
Up Next
How to Auto Search Data From Database in C# .Net