Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi in my winform application am displaying records in datagrid..and one textbox is there.when i enter name of the person in text box that record should display in datagrid.or display messg as record not found..?
i tried this code for Text Changed



in text change:
C#
dv.RowFilter = "FirstName like '%" + textBox1.Text + "%'";
dataGridView1.DataSource = dv;


C#
public DataSet ds
{
    get;
    set;
}

public DataView dv
{
    get;
    set;
}

C#
public Form1()
{
    InitializeComponent();
    ds = new DataSet();
   dv = new DataView();
}



am not able to display records..when i enter first name in text box that time records not displaying in grid....
can any one suggest me.and better code for this??

thanks..
Posted
Updated 12-Aug-12 0:47am
v2

1 solution

try this code on
C#
private void textBox1_TextChanged(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from Table1 where FirstName Like '" + textBox1.Text + "%' ", con);
SqlDataAdapter da= new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
da.SelectCommand.ExecuteNonQuery();
con.Close();
}

Raj
 
Share this answer
 
v2
Comments
Raje_ 12-Aug-12 7:36am    
+5 for win app.
ythisbug 12-Aug-12 8:31am    
thanks and how can i display message if perticular Name not found in datagrid?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900