To implement this concept you need to follow the below steps :
Step1 :
First you need to design a table in MS Access 2007 Database to retrieve the records from
database.
Step2:
On the File menu, click New
Project. Select Windows Forms Application as
your project type.
Design the Form using controls from Toolbox.
Step3:
Now open the Form.cs page and write the following source code.
Form.cs 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 System.Data.OleDb;
namespace Visiting_Card
{
public partial class Form2 : Form
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=E:\VisitingCard.accdb");
public Form2()
{
InitializeComponent();
}
private void btnSearch_Click(object sender, EventArgs e)
{
con.Open();
OleDbCommand cmd1 = new OleDbCommand("VisitingCard_Search", con);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.AddWithValue("@Names",
txtKeyword.Text);
OleDbDataAdapter da = new OleDbDataAdapter(cmd1);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
}
}
Step4:
Now build the Solution and Debug it for the output.
OutPut :
Good Day
ReplyDeleteWhat if using combobox not button, will auto filter the name in datagridview.... For enrollment.. Using C# OleDb as database
For Example:When typing in combobox subject "English" the datagridview will auto filter all "English"..
Thank you!!!