Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when I am searching for some records in gridview, the error message is showing like
"Specified argument was out of the range of valid values"

the code is:
C#
con.Open();
string query = "select Name from View where ID like'" + txtID.Text +"%'";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
    GridViewItm.DataSource = ds;
    GridViewItm.DataBind();
    GridViewItm.Show();
}
else
{
    Response.Write(@"<script language='javascript'>alert('Requested Records Not Found')</script>");
}

So please,, anyone suggest me some answers...
Posted
Updated 4-Sep-13 21:15pm
v2
Comments
Mohan Gopi 5-Sep-13 2:38am    
Exactly where your getting error. you can't give dataset as a Gridvew Datasource. you can try
GridViewItm.DataSource = ds.Tables[0];
Thanks7872 5-Sep-13 3:01am    
MohanGopi wrote:
you can't give dataset as a Gridvew Datasource.


Are you sure?
Mohan Gopi 5-Sep-13 3:17am    
i am not sure but i have tried in windows application not in web.
Thanks7872 5-Sep-13 3:19am    
Well,you can have dataset as a gridview datasource.
Priyanka Bhagwat 5-Sep-13 2:43am    
have you checked your query

i don't know well..

but, i have idea.

con.Open();
 string query = "select Name from View where ID like'" + txtID.Text +"%'";
 SqlDataAdapter da = new SqlDataAdapter(query, con);
 DataSet ds = new DataSet();
 da.Fill(ds);
 if (ds.Tables[0].Rows.Count > 0)
 {
 GridViewItm.DataSource = ds.Tables[0];  // Edit!
 }
 else
 {
 Response.Write(@"<script language='javascript'>alert('Requested Records Not Found')</script>");
 }
 
Share this answer
 
v2
1. Check whether the DataSet contains Table and handle it If does not.
2. If the DataSet has Table then check the Table has rows.
3. Finally Bind the DataSet to the GridView Datasource like ds.Tables[0];
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900