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);
}
}
{
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

VulpesRank #55 · 29.2K reputationPosted May 2, 2014, 12:44 AM EDT
if (temp.Length == 2) ValueArray[1] = temp[1];
Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted May 1, 2014, 10:32 PM EDT
Gopal Ji Singh39 reputationPosted May 1, 2014, 10:44 PM EDT
Munesh SharmaRank #174 · 13.9K reputationPosted May 2, 2014, 1:24 AM EDT
string strinfo;
strinfo= "name,city,email";
};
Gopal Ji Singh39 reputationPosted May 3, 2014, 12:23 AM EDT