Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sirs/Madams,

I had created a form in which, I had inserted a DataGridView. And aslo I am having the "first, middle and last" labels with there TextBoxes and one search Button. So what I want is, if I enter the name in TextBox of "first" label and hit a search button, its row as to be displayed in DataGridView.

So I have to add the query in "DataGridView Task", or I have to write query inside "GridView".

This is my code:

C#
namespace Config_admin
{
    public partial class Form2 : Form
    {
        SqlConnection con;
        SqlCommand com;
        SqlDataReader rdr;
        DataSet ds;
        SqlDataAdapter da;
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            con = new SqlConnection("Data Source=CBP\\SQLEXPRESS;Initial Catalog=ECG;Integrated Security=True");
            con.Open();
            com = new SqlCommand("select middle,last from  Table2 where first= '"+ textBox1.Text.Trim()+"'",con);
            rdr = com.ExecuteReader();
            bool temp = false;
            while (rdr.Read())
            {

                //textBox1.Text = rdr.GetString(0);
                comboBox1.Text = rdr[0].ToString().Trim();//ToString();// GetString(1);
                comboBox2.Text = rdr[1].ToString().Trim();
                //textBox4.Text = rdr.GetString(3);
                //textBox5.Text = rdr.GetString(4);
                //textBox6.Text = rdr.GetString(5);
                //textBox7.Text = rdr.GetString(6);
                //textBox8.Text = rdr.GetString(7);
                //textBox9.Text = rdr.GetString(8);
                //textBox10.Text = rdr.GetString(9);
                temp = true;

            }
            
            if (temp == false)
                MessageBox.Show("not found");
            con.Close();

            con.Open();
            ds = new DataSet();
            da = new SqlDataAdapter("select * from Table2", con);
            da.Fill(ds, "Table2");
            con.Close();


        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }



Please help me in this regard

Thanks
Pradeep CBZ
Posted
Updated 13-Mar-12 1:11am
v2
Comments
Shahin Khorshidnia 13-Mar-12 8:01am    
Hello Pradeep CBZ

I have reviewed this and your previous questions.

I hope you won't mind me reminding you:

1. Please pay attention to your typing. You have enough time to use "and", "you", "please", ... instead of "&", "u", "plz"

2. If the experts answer your question, It will be better to accept the correct answer(s), otherwise the question will stay as unaswered in the site. Accepting the correct answer is also a bare "thank you" to the expert who is helping you. It seems you are not disposed toward accepting because the only solution that you have accepted, was your own solution! I keep wondering about you can't find your answer here, but you are asking again and again?!(!) ;)


3. If you want to give an example of your code, then don't type it like a normal text. You can select it >> click on "code" (top of the page)>> Choose the spesific language. It makes it clear. Don't wait for editors.

Thank you

1 solution

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