Sir, I am currently doing a project on "Pharmacy Management System". My question is "Can I used DataGridView to show the items that i have searched and the rest won't be visible??" If yes then can anyone give me the code for search button?? I have used the following code but its not working...please help ASAP....

private void button7_Click(object sender, EventArgs e)
            dataGridView1.Visible = true;
            string connectionstring = "Data Source=DEBO-PC;Initial Catalog=Pharmacy;Persist Security Info=True;User ID=sa;Password=niit@123";
            SqlConnection con = new SqlConnection(connectionstring);
            SqlCommand cm = new SqlCommand();
            string search_text = "Select * from Stock_Details where Batch_Number like '%" + textBox1.Text + "%'" + "or Medicine_Name like '%" + textBox1.Text + "%'" + "or Mfg_Company like'%" + textBox1.Text + "%'";
            DataSet ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter(search_text, con);
            dataGridView1.DataSource = ds.Tables[0];

When you say you do not want the 'rest' to be visible what exactly is the rest? Extra rows from the database? Other controls on the screen? What?
If it is rows from the database simply alter your SQL statement to select only the rows you want instead of using *.

If you use the * in your search staement, you ask for and get everything. Remove the * and only list the columns you want.
e.g. SELECT Batch_Number, Medicine_Name, Mfg_Company FROM


You can mention the fied which you require to display in your query, likewise in gridview if you find any empty data cell for the rest of the column you can clear it by particular cell index.

Hopes this wud help you,

This article has been dead for over six months. Start a new discussion instead.