Click here to Skip to main content
15,902,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
SqlParameter[] parameters = new SqlParameter[1];
           parameters[1] = DataLayer.DataAccess.AddParameter("@CategoryID", CategoryID, System.Data.SqlDbType.Int, 20);
           DataTable dt = DataLayer.DataAccess.ExecuteDTByProcedure("SP_GetAllProducts", parameters);
           return dt;


What I have tried:

I got a now another error index was outside the bounds of the array, please any one give me ideas. How to solve this error.
Posted

The array is 0 based not 1, the first element is 0.

C#
SqlParameter[] parameters = new SqlParameter[1];
           parameters[0] = DataLayer.DataAccess.AddParameter("@CategoryID", CategoryID, System.Data.SqlDbType.Int, 20);
           DataTable dt = DataLayer.DataAccess.ExecuteDTByProcedure("SP_GetAllProducts", parameters);
           return dt;


Why have an array when there is only 1?
 
Share this answer
 
v2
Comments
Boopalslm 16-Feb-16 2:05am    
pnlProducts.Visible = true;
int CategoryID = Convert.ToInt16((((LinkButton)sender).CommandArgument));
GetProducts(CategoryID);

k working but now above line are error, Input string was not in a correct format, how to solve this problem.
Michael_Davies 16-Feb-16 2:12am    
Use the debugger and look at the content of CommandArgument Convert.ToInt16 expects only numerals.
Boopalslm 16-Feb-16 2:22am    
if you possible please modify my above code and send me.
Michael_Davies 16-Feb-16 2:25am    
There is no modification to your code, check the actual contents of CommandArgument using the debugger.
Boopalslm 16-Feb-16 2:27am    
k i will check once
Arrays are 0-based in C#. So if you allocate an array with a length of 1, your first (and only) valid index is 0:
C#
SqlParameter[] parameters = new SqlParameter[1];
parameters[0] = ...
 
Share this answer
 
C#
parameters[0] = DataLayer.DataAccess.AddParameter("@CategoryID", CategoryID, System.Data.SqlDbType.Int, 20);
 
Share this answer
 
C# language is 0 based.
It simply mean that every array start at index 0.
An array of size 1 can only use index 0.
Array of size 1 have no interest, it just complicate the syntax.
 
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