-1

This is my first question: The SqlParameter is already contained by another SqlParameterCollection. SqlDataReader rdr[0] vs. object brings me table columns values.

    public ArrayList[] GetInfo(string sqlCommand, SqlParameter sqlParameter)
    {
        ArrayList[] drawingInfo = new ArrayList[7];
        drawingInfo[0] = new ArrayList();
        drawingInfo[1] = new ArrayList();
        drawingInfo[2] = new ArrayList();
        drawingInfo[3] = new ArrayList();
        drawingInfo[4] = new ArrayList();
        drawingInfo[5] = new ArrayList();
        drawingInfo[6] = new ArrayList();
        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 drawingInfo;
        }
    }
hikmet_anil
  • 89
  • 3
  • 14
  • 1
    what is the value of the sqlParameter you are passing also what is the datatype. – MethodMan Mar 17 '15 at 19:14
  • SqlParameter value=listBox1.SelectedValue; I solved my problem.When i call the method ( GetInfo() ) I have to create every time new SqlParameter . Actually my question code is not include an error. Thanks – hikmet_anil Mar 17 '15 at 19:45

1 Answers1

0

You cant call GetInfo method twice with the same object as parameter. Pass only value to the method and build the SqlParameter each time again. The same as you do with SqlCommand.

Jan Zahradník
  • 2,417
  • 2
  • 33
  • 44
  • Yes, I solved . When i call the method I have to create every time new SqlParameter . Actually my question code is not include an error. Thanks. – hikmet_anil Mar 17 '15 at 19:39