Thursday 15 March 2012

c# - The SqlParameter is already contained by another SqlParameterCollection.3 -


itemprop = "text">

This is my first question: SqlParameter is already contained by another SqlParameterCollection SqlDataReader rdr [0] vs Object I get table column value I

  Public array list [] GetInfo (string sqlCommand, SqlParameter sqlParameter) {ArrayList [] drawingInfo = New ArrayList [7]; Drawinginfo [0] = new arrelist (); Drawinginfo [1] = new arrivate (); Drawinginfo [2] = new Arrayist (); Drawinginfo [3] = new Arrayist (); Drawinginfo [4] = new Arrayist (); Drawinginfo [5] = new Arrayist (); Drawinginfo [6] = new Arrayist (); (Using SqlConnection con = new SqlConnection ("connectionAdres")) {SqlCommand cmd = new SqlCommand (); Cmd.Connection = con; Cmd.CommandText = sqlCommand; Cmd.CommandType = CommandType.StoredProcedure; Cmd.Parameters.Add (SqlParameter); Con.Open (); SqlDataReader rdr = cmd.ExecuteReader (); While (rdr.Read ()) {drawingInfo [0]. Add (RDR [0]); DrawingInfo [1] .Add (RDR [1]); DrawingInfo [2] .Add (RDR [2]); DrawingInfo [3] .Add (RDR [3]); DrawingInfo [4] .Add (RDR [4]); DrawingInfo [5] .Add (RDR [5]); DrawingInfo [6] .Add (RDR [6]); } Return drawing information; }}  

You do not call GetInfo method twice with the same object of the parameter Can. Just pass the value to the method and create SqlParameter every time. As you do with SqlCommand.


No comments:

Post a Comment