Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:02:29+00:00 2026-06-05T10:02:29+00:00

I am getting desperate here. I cant figure out why does this exception occur.

  • 0

I am getting desperate here. I cant figure out why does this exception occur. I searched and read about this problem and it seems everyone managed to solve it with command.Parameters.Clear(), but this does not work for me. Here is my code:

    public class ProductsDataAccess : Connection 
{
    public static SqlParameter[] createParams(Products prod)
    {
        SqlParameter idParam = new SqlParameter("@id", prod.prodID);
        idParam.SqlDbType = System.Data.SqlDbType.VarChar;
        idParam.Size = 45;
        idParam.IsNullable = false;
        idParam.Direction = ParameterDirection.Input;

        SqlParameter nameParam = new SqlParameter("@name", prod.prodName);
        nameParam.SqlDbType = System.Data.SqlDbType.VarChar;
        nameParam.Size = 45;
        nameParam.IsNullable = false;
        nameParam.Direction = ParameterDirection.Input;

        SqlParameter demandParam = new SqlParameter("@demand", prod.demand);
        demandParam.SqlDbType = System.Data.SqlDbType.Int;
        demandParam.IsNullable = false;
        demandParam.Direction = ParameterDirection.Input;

        SqlParameter demandLTParam = new SqlParameter("@demandLT", prod.demandLT);
        demandLTParam.SqlDbType = System.Data.SqlDbType.Int;
        demandLTParam.IsNullable = false;
        demandLTParam.Direction = ParameterDirection.Input;

        SqlParameter leadTimeParam = new SqlParameter("@leadTime", prod.leadTime);
        leadTimeParam.SqlDbType = System.Data.SqlDbType.Int;
        leadTimeParam.IsNullable = false;
        leadTimeParam.Direction = ParameterDirection.Input;

        SqlParameter fixedCoastParam = new SqlParameter("@k", prod.k);
        fixedCoastParam.SqlDbType = System.Data.SqlDbType.Float;
        fixedCoastParam.IsNullable = false;
        fixedCoastParam.Direction = ParameterDirection.Input;

        SqlParameter cParam = new SqlParameter("@c", prod.c);
        cParam.SqlDbType = System.Data.SqlDbType.Float;
        cParam.IsNullable = false;
        cParam.Direction = ParameterDirection.Input;

        SqlParameter chPrecentageParam = new SqlParameter("@chPrecent", prod.precentOfC);
        chPrecentageParam.SqlDbType = System.Data.SqlDbType.Int;
        chPrecentageParam.IsNullable = false;
        chPrecentageParam.Direction = ParameterDirection.Input;

        SqlParameter chParam = new SqlParameter("@ch", prod.ch);
        chParam.SqlDbType = System.Data.SqlDbType.Float;
        chParam.IsNullable = false;
        chParam.Direction = ParameterDirection.Input;

        SqlParameter optimalQParam = new SqlParameter("@q", prod.q);
        optimalQParam.SqlDbType = System.Data.SqlDbType.Int;
        optimalQParam.IsNullable = false;
        optimalQParam.Direction = ParameterDirection.Input;

        SqlParameter annualChParam = new SqlParameter("@annualCh", prod.annualCh);
        annualChParam.SqlDbType = System.Data.SqlDbType.Float;
        annualChParam.IsNullable = false;
        annualChParam.Direction = ParameterDirection.Input;

        SqlParameter annualKParam = new SqlParameter("@annualK", prod.annualK);
        annualKParam.SqlDbType = System.Data.SqlDbType.Float;
        annualKParam.IsNullable = false;
        annualKParam.Direction = ParameterDirection.Input;

        SqlParameter optimalTACParam = new SqlParameter("@tac", prod.tac);
        optimalTACParam.SqlDbType = System.Data.SqlDbType.Float;
        optimalTACParam.IsNullable = false;
        optimalTACParam.Direction = ParameterDirection.Input;

        SqlParameter rParam = new SqlParameter("@r", prod.r);
        rParam.SqlDbType = System.Data.SqlDbType.Int;
        rParam.IsNullable = false;
        rParam.Direction = ParameterDirection.Input;

        SqlParameter inventoryLvlParam = new SqlParameter("@invLvl", prod.inventoryLvl);
        inventoryLvlParam.SqlDbType = System.Data.SqlDbType.Int;
        inventoryLvlParam.IsNullable = false;
        inventoryLvlParam.Direction = ParameterDirection.Input;

        SqlParameter statusParam = new SqlParameter("@status", prod.status);
        statusParam.SqlDbType = System.Data.SqlDbType.VarChar;
        statusParam.Size = 10;
        statusParam.IsNullable = false;
        statusParam.Direction = ParameterDirection.Input;

        SqlParameter[] paramList = {idParam, nameParam, demandParam, demandLTParam,
                                   leadTimeParam, fixedCoastParam, cParam,
                                   chPrecentageParam, chParam, optimalQParam,
                                   annualChParam, annualKParam, optimalTACParam, 
                                   rParam, inventoryLvlParam, statusParam };
        return paramList;

    }

    public static void insertProduct(Products product)
    {


        String comStr = "insert into Products(prodID, name, demand, demandLT, leadTime, fixedCoast, " + 
            "c, chAsPrecentage, ch, optimalQ, annualCh, annualK, optimalTAC, r, inventoryLvl, prodStatus) " + 
            "values(@id, @name, @demand, @demandLT, @leadTime, @k, @c, @chPrecent, " + 
            "@ch, @q, @annualCh, @annualK, @tac, @r, @invLvl, @status)";

        createConncetion();

        SqlCommand command = new SqlCommand(comStr, con);
        command.Parameters.AddRange(createParams(product));

        openConnection();

        command.ExecuteNonQuery();
        closeConnection();

        command.Parameters.Clear()
        command.Dispose();
    }

    public static DataTable getAllProducts()
    {
        String comStr = "select prodID, name, demand, demandLT, leadTime, fixedCoast, c, chAsPrecentage, " + 
            "ch, optimalQ, annualCh, annualK, optimalTAC, r, inventoryLvl, prodStatus from Products";

        createConncetion();

        SqlCommand command = new SqlCommand(comStr, con);

        DataTable table = new DataTable("allProduct");
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand=command;

        openConnection();

        adapter.Fill(table);
        command.Dispose();
        closeConnection();
        return table;
    }

}

Here is the other class in which I am using sqlParameters:

    public class StatisticsDataAccess : Connection
{

    public static SqlParameter[] createParams(Statistics stat, string prodID)
    {

        SqlParameter idParam = new SqlParameter("@id", prodID);
        idParam.SqlDbType = System.Data.SqlDbType.VarChar;
        idParam.Size = 45;
        idParam.IsNullable = false;
        idParam.Direction = ParameterDirection.Input;

        SqlParameter m1Param = new SqlParameter("@m1", stat.month1);
        m1Param.SqlDbType = System.Data.SqlDbType.Int;
        m1Param.IsNullable = false;
        m1Param.Direction = ParameterDirection.Input;

        SqlParameter m2Param = new SqlParameter("@m2", stat.month2);
        m2Param.SqlDbType = System.Data.SqlDbType.Int;
        m2Param.IsNullable = false;
        m2Param.Direction = ParameterDirection.Input;

        SqlParameter m3Param = new SqlParameter("@m3", stat.month3);
        m3Param.SqlDbType = System.Data.SqlDbType.Int;
        m3Param.IsNullable = false;
        m3Param.Direction = ParameterDirection.Input;

        SqlParameter m4Param = new SqlParameter("@m4", stat.month4);
        m4Param.SqlDbType = System.Data.SqlDbType.Int;
        m4Param.IsNullable = false;
        m4Param.Direction = ParameterDirection.Input;

        SqlParameter m5Param = new SqlParameter("@m5", stat.month5);
        m5Param.SqlDbType = System.Data.SqlDbType.Int;
        m5Param.IsNullable = false;
        m5Param.Direction = ParameterDirection.Input;

        SqlParameter m6Param = new SqlParameter("@m6", stat.month6);
        m6Param.SqlDbType = System.Data.SqlDbType.Int;
        m6Param.IsNullable = false;
        m6Param.Direction = ParameterDirection.Input;

        SqlParameter m7Param = new SqlParameter("@m7", stat.month7);
        m7Param.SqlDbType = System.Data.SqlDbType.Int;
        m7Param.IsNullable = false;
        m7Param.Direction = ParameterDirection.Input;

        SqlParameter m8Param = new SqlParameter("@m8", stat.month8);
        m8Param.SqlDbType = System.Data.SqlDbType.Int;
        m8Param.IsNullable = false;
        m8Param.Direction = ParameterDirection.Input;

        SqlParameter m9Param = new SqlParameter("@m9", stat.month9);
        m9Param.SqlDbType = System.Data.SqlDbType.Int;
        m9Param.IsNullable = false;
        m9Param.Direction = ParameterDirection.Input;

        SqlParameter m10Param = new SqlParameter("@m10", stat.month10);
        m10Param.SqlDbType = System.Data.SqlDbType.Int;
        m10Param.IsNullable = false;
        m10Param.Direction = ParameterDirection.Input;

        SqlParameter m11Param = new SqlParameter("@m11", stat.month11);
        m11Param.SqlDbType = System.Data.SqlDbType.Int;
        m11Param.IsNullable = false;
        m11Param.Direction = ParameterDirection.Input;

        SqlParameter m12Param = new SqlParameter("@m12", stat.month12);
        m12Param.SqlDbType = System.Data.SqlDbType.Int;
        m12Param.IsNullable = false;
        m12Param.Direction = ParameterDirection.Input;

        SqlParameter[] paramList = {idParam, m1Param, m2Param, m3Param, m4Param,
                                   m5Param, m6Param, m7Param, m8Param, m8Param,
                                   m10Param, m11Param, m12Param };
        return paramList;
    }

    public static void insertStatistic(Statistics stat, string prodID)
    {


        String comStr = "insert into LTDStatistic(prodID, month1, month2, month3, month4, month5, " +
            "month6, month7, month8, month9, month10, month11, month12)" +
            "values(@id, @m1, @m2, @m3, @m4, @m5, @m6, @m7, @m8, @m9, @m10, @m11, @m12)";

        createConncetion();

        SqlCommand command = new SqlCommand(comStr, con);
        command.Parameters.AddRange(createParams(stat, prodID));

        openConnection();

        command.ExecuteNonQuery();
        closeConnection();
        command.Parameters.Clear();
        command.Dispose();

    }

}

WCF Service uses methods from those classes in order to modify a data base

        public void create(ProductsData product)
    {

        Statistics statDLT = new Statistics(product.demandLTStat.month1, product.demandLTStat.month2,
            product.demandLTStat.month3, product.demandLTStat.month4, product.demandLTStat.month5,
            product.demandLTStat.month6, product.demandLTStat.month7, product.demandLTStat.month8,
            product.demandLTStat.month9, product.demandLTStat.month10, product.demandLTStat.month11,
            product.demandLTStat.month12);

        Products newProd = new Products(product.prodID, product.prodName,
            product.leadTime, product.k, product.c, product.precentOfC, 
            product.demand, statDLT);

        newProd.callculate();
        newProd.determineR();
        ProductsDataAccess.insertProduct(newProd);
        //String plsWork = newProd.prodID;
        StatisticsDataAccess.insertStatistic(newProd.demandLTStat, newProd.prodID);
    }

Maybe Im missing some important aspect of how things work … I dont know. Hope someone can help me, and sorry for the long code segments.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:02:31+00:00Added an answer on June 5, 2026 at 10:02 am

    m8Param occurs twice in the array returned by StatisticsDataAccess.createParams().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm a real novice at android and really getting desperate at this apparently
Hey, I'm desperate right here. jQuery: $(.rotateme li a).click(function(){ var curid = $(this).attr('id'); $('#box'+curid).fadeIn('slow');
I am getting really desperate here. I working with Xcode, trying to implement some
I'm getting kind of desperate here trying to get mysql to work on osx
I'm getting desperate trying to get the jQuery mobile pagebeforeload event to fire. This
Getting this error when I follow the simple code example from jsoncpp, that basically
I'm getting close to desperate.. I am developing a field service application for Windows
I've spent many hours trying to get this to work. And I'm getting quite
I'm running Windows 7 64 bit, which seems to be part of the problem.
I have spent three days trying to find the solution to this problem to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.