locked
How to pass collection of parameters into Data Access Block RRS feed

  • Question

  • User1119954915 posted
    When using "CommandType.Text"???? Anytime i try to dynamically add parameters like: Dim arrParams As New ArrayList arrParams.Add(New SQLParamter("@Param1", "Value1")) arrParams.Add(New SQLParamter("@Param2", "Value2")) arrParams.Add(New SQLParamter("@Param3", "Value3")) arrParams.Add(New SQLParamter("@Param4", "Value4")) .... and so on.. it could vary in # of parameters .... Variable "strSQL" gets built so it looks like: UPDATE Table SET Col1 = @Param1, Col2 = @Param2, etc etc Then i present it to the Access Blocks: RetVal = SqlHelper.ExecuteScalar(GetConnectionString(), CommandType.Text, _ strSQL, arrParams.ToArray(GetType(SqlParameter))) The Access blocks automatically assume i am using a PROC because it throws the error: "The stored procedure '1' doesn't exist." which means it is desperately trying to use this overloaded method: ExecuteScalar(connectionString As String, spName As String, ParamArray parameterValues() As Object) As Object despite clear as day me trying to use: ExecuteScalar(connectionString As String, commandType As System.Data.CommandType, commandText As String, ParamArray parameterValues() As System.Data.SqlClient.SqlParameter) As Object hopefully someone has a solution for me.... a PROC is not an option here, this call could be 2 fields to update, it could be 100... and i am out of answers :(
    Tuesday, July 20, 2004 12:16 PM

All replies

  • User-1638510185 posted
    Whenever I have these types of problems, I debug thru the SqlHelper routines to determine the cause of the problem.
    Sunday, July 25, 2004 5:09 PM
  • User1518929954 posted
    In case anyone cares about the solution, it was this for vb: Dim pArray() As SqlParameter = CType(pList.ToArray(GetType(SqlParameter)), SqlParameter()) And this for c#: SqlParameter[] pArray = (SqlParameter[])al.ToArray(typeof(SqlParameter));
    Sunday, September 26, 2004 12:31 AM
  • User-275659039 posted
    Thanks Scott, it helped me.
    Monday, November 15, 2004 10:21 AM