sureshcd10 Posted May 9, 2004 Posted May 9, 2004 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: Quote ima
Administrators PlausiblyDamp Posted May 9, 2004 Administrators Posted May 9, 2004 Public Sub MyFunction(ByVal Procdurename As String, ByVal ParamArray params() As String) Dim s As String For Each s In params Next End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.