Gopal Ji  Singh

Gopal Ji Singh

  • NA
  • 39
  • 31.7k

Error : Index was outside the bounds of the array

May 2 2014 2:28 AM
Hi
 
There is a problem in my code and i am not aware how to resolve this .
My Error is  Index was outside the bounds of the array. when i am passing 1 or 2 value in textbox it gives error and when i am passing 3 or more than 3 value in textbox it is working fine so please help me and resolve my problem if anybody can .
 
My Code is
protected void btnsearch_Click(object sender, EventArgs e)
{
try
{
string shortWord = txtsearch.Text;
//split the text Into Seperate Words
string delimstr = ",";
char[] delimiter = delimstr.ToCharArray();
string[] ValueArray = shortWord.Split(delimiter);
SqlCommand cmd = new SqlCommand("select * from Rgisterbasic where name like '%" + ValueArray[0].Trim() + "%' and city like '%" + ValueArray[1].Trim() + "%' and email like '%" + ValueArray[2].Trim() + "%'", con);

SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
 
 
 
Thanks
Gopal

Answers (5)