Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I got index out of range exception, below my code please help me.
C#
SqlDataAdapter adp = new SqlDataAdapter(command);
adp.Fill(ds);
strReturn = Convert.ToString(ds.Tables[0].Rows[0][1]);
Posted
Updated 13-Feb-13 20:51pm
v2
Comments
Karthik Harve 14-Feb-13 2:51am    
[Edit] added pre tags
Naveen.Sanagasetti 14-Feb-13 3:40am    
Put a break point in your code and check the "ds" having Table "0" or not.

Hi,

debug not working in visual studio 2010. so I can't debug my code.
 
Share this answer
 
Hi,

debug not working in visual studio 2010. so I can't debug my code.
adp.Fill(ds); // Data table check
//System.IndexOutOfRangeException: Cannot find table 0.
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Rows[0][1] != DBNull.Value)
{
strReturn = Convert.ToString(ds.Tables[0].Rows[0][1]);
}
 
Share this answer
 
Comments
Naveen.Sanagasetti 14-Feb-13 4:56am    
Any doubt's use "Have a Question or comment" button.
I think the problem is your DataSet doesn't have a Table[0].
debug is possible for VS2010, if it's not possible to you, Execute your SQL query and check the result status it's return the result set or not checkout that. May be your SQL query doesn't return any thing. So, your dataset doesn't have a data , without data you try to call the dataset table[0]. It's automatically through the error "IndexOutOfRangeException: Cannot find table 0".
 
Share this answer
 

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