Jump to content
Xtreme .Net Talk

How to Create a Function that accepts different number ofparameters based on a number


Recommended Posts

Posted

I ve got two buttons on my WebForm with the following code behind them

Private sub Button1_Click(......)...

cmdsql = New SqlClient.SqlCommand("ProcedureName", con)

cmdsql.CommandType = CommandType.StoredProcedure

cmdsql.Parameters.Add("@Id1", Id1)

cmdsql.Parameters.Add("@Id2", Id2)

end sub

 

Private sub Button2_Click(......)...

cmdsql = New SqlClient.SqlCommand("ProcedureName", con)

cmdsql.CommandType = CommandType.StoredProcedure

cmdsql.Parameters.Add("@Id1", Id1)

cmdsql.Parameters.Add("@Id2", Id2)

cmdsql.Parameters.Add("@Id3", Id3)

cmdsql.Parameters.Add("@Id4", Id4)

end sub

 

Now I want to replace the code between the two ButtonClik events with a common function

Is it possible to write such a function ? How ?

 

ie Like the following

so that I can write like this

 

Private sub Button1_Click(......)...

MyFunction("ProcedureName",2,"@Id1","@Id2",Id1,Id2)

end sub

 

Private sub Button2_Click(......)...

MyFunction("ProcedureName",3,"@Id1","@Id2","@Id3",Id1,Id2,Id3)

end sub

 

 

Public Function MyFunction(Procdurename as String,n as Integer,y as String,z as String)

dim i as integer

for i=1 to n

......

next

end function

 

suppose if I am giving 2 as the value on n,then myFunction should allow me to pass 2 parameters(ie 2 values for y and 2 values for z)

and if I am giving 3 as the value on n,then myFunction should allow me to pass 3 parameters(ie 2 values for y and 2 values for z)

 

Any one having an idea to create such a function ....

 

Thanks in advance :confused: :confused: :confused:

ima

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...