sadanandams 0 Newbie Poster

Hi evryone, am working on datagridview contains a textbox and a combobox.

 string msql="Select * from Supplier";
 private void txtgridsearch_TextChanged(object sender, EventArgs e)
 {
            objcon = new SqlConnection(objconstring);
            objcon.Open();
            objcmd = new SqlCommand("INV_SP_Search_Supplier", objcon); 
            objcmd.Parameters.Add("@supplierid", SqlDbType.Int, 0, "supplierid");
            objcmd.Parameters.Add("@companyname", SqlDbType.VarChar, (50),"companyname");
            objcmd.Parameters.Add("@contactname", SqlDbType.VarChar, (50),"contactname");           
            objda = new SqlDataAdapter(objcmd);
            objds = new DataSet();
            objda.Fill(objds, "supplier"); 
            objcon.Close();  
 }

 private void cmbgridsearchby_SelectedIndexChanged(object sender, EventArgs e)
 {
            string sql = msql;
            if (cmbgridsearchby.Text == "SupplierID")
            {
                if (txtgridsearch.Text != "")
                {
                    sql += " Where SupplierID=" + txtgridsearch.Text;
                }
            }
            else if (cmbgridsearchby.Text == "CompanyName")
            {
                sql += " Where CompanyName Like '" + txtgridsearch.Text + "%'";
            }
            else if (cmbgridsearchby.Text == "ContactName")
            {
                sql += " Where ContactName Like '" + txtgridsearch.Text + "%'";
            }
}

how do i search a record in datagridview from combobox selection throw entering a record name in textbox. Pls check is this code correct??

mani-hellboy commented: use code block +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.