Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have declared a SqlParameter Araay (SqlParameter[] paramFields = new SqlParameter[100]). And i am initializing the Arraay as below.

C#
SqlParameter[] getFormId = 
{ new SqlParameter("@fid1", SqlDbType.VarChar, 50) { Value = fID1 }
new SqlParameter("@fid2", SqlDbType.VarChar, 50) { Value = fID2 }
new SqlParameter("@fid3", SqlDbType.VarChar, 50) { Value = fID3 }
new SqlParameter("@fid4", SqlDbType.VarChar, 50) { Value = fID4 } };



I want to clear the array getFormId for reuse.
How can i clear it.?
Posted
Updated 1-Jul-15 2:02am
v3

Try this-
C#
getFormId = new SqlParameter(1) {}


Hope, it helps :)
 
Share this answer
 
This is pretty much trivial using Array.Clear

C#
Array.Clear(getFormId,0,getFormId.Length);


You can use that method to truncate or completely empty an array, documentation can be found at:
https://msdn.microsoft.com/en-us/library/system.array.clear(v=vs.110).aspx[^]
 
Share this answer
 
Comments
Merajuddin Ansari 1-Jul-15 8:12am    
thanks it hepled me.
C#
getFormId = null;

- or -
C#
getFormId = new SqlParameter[100];


While I commend you for parametrizing your SQL, I strongly urge to take a closer look at what you are doing. A query with 100 parameters is a huge red flag and screams refactor to a better solution.
 
Share this answer
 
Comments
Merajuddin Ansari 1-Jul-15 8:14am    
can you please tell me the alternative of this.?

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