Error in parameters

1

I have the following query, I have to show the records in a gridview but this error marks me, "The input string does not have the correct format."

I have parameters in string and an integer

App_Data.DataSet1TableAdapters.PS_USR_ConsultaExternaTableAdapter adapter = new App_Data.DataSet1TableAdapters.PS_USR_ConsultaExternaTableAdapter();

            adapter.GetData("", "", "", int.Parse(this.TextBox1.Text));
this.gvbuscar.DataSource = adapter.GetData("", "", "", int.Parse(this.TextBox1.Text));
            this.gvbuscar.DataBind();
    
asked by KlonDTS 06.12.2016 в 20:14
source

1 answer

0

I think the problem when trying to convert the content of TextBox to whole, in some cases apparently the content is not numeric and causes the error:

int.Parse(this.TextBox1.Text)

you can validate using int.TryParse() :

Example:

    //Si el valor no es númerico asigna un default con valor de 0.
    int valorTextBox = int.TryParse(this.TextBox1.Text, out valorTextBox) ? valorTextBox: 0;

    adapter.GetData("", "", "", valorTextBox);
    this.gvbuscar.DataSource = adapter.GetData("", "", "", valorTextBox));
    this.gvbuscar.DataBind();
    
answered by 06.12.2016 / 20:26
source