[Solved] C# Argument cannot convert int to string or string to int


You could also usefully do with some error handling on the text box conversions – it is never a good plan to take a text box and expect the user to simply enter valid data:

    private void buttonSearch_Click(object sender, EventArgs e)
    {

        bool process = true;
        String prodName = textBoxName.Text;
        int prodID;
        double prodPrice;
        try
        {
            prodID = Convert.ToInt32(textBoxID.Text);
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message, "Error in product ID", MessageBoxButtons.OK, MessageBoxIcon.Error);
            process = false;        
        }
        try
        {
            prodPrice = Convert.ToDouble(textBoxPrice.Text);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error in product price", MessageBoxButtons.OK, MessageBoxIcon.Error);
            process = false;

        }
        if (process)
        {
            SearchProducts(prodID);
            SearchProducts(prodName);
            SearchProducts(prodID, prodName, prodPrice);
        }
    }

Edit:

I did forget to say that you could replace Convert with the class parsers, this avoids the need for a try/catch:

if (!Int32.TryParse(textBoxID.Text, out prodID))
{
    process = false;
    // message method of choice to tell user of error
}

solved C# Argument cannot convert int to string or string to int