Error:Index (zero based) must be greater than or equal to zero and less than the size of the argument list

16,087

I assume this

string a = string.Format("select * from upnotice where show like '{0}' ,%t");

should be

string a = string.Format("select * from upnotice where show like '{0}'","%t");

Every format item(e.g. {0} or {1}) needs to have a corresponding argument.

However, you should not use string.Format but sql-parameters to prevent sql-injection.

Share:
16,087

Related videos on Youtube

Shiv Narwariya
Author by

Shiv Narwariya

Updated on June 05, 2022

Comments

  • Shiv Narwariya
    Shiv Narwariya almost 2 years
    SqlConnection cn = new SqlConnection("server=localhost;initial catalog=newmits;trusted_connection=true");
    cn.Open();
    string a = string.Format("select * from upnotice where show like '{0}' ,%t");
    SqlDataAdapter adp1 = new SqlDataAdapter(a, cn);
    DataSet ds1 = new DataSet(); 
    adp1.Fill(ds1);
    GridView1.DataSource = ds1;
    GridView1.DataBind();
    

    When I try without where condition it works but with where it does not work pls help me