1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

The variable name '@' has already been declared. Variable names must be unique within a query...

Discussão em 'Outras Linguagens' iniciado por Stack, Julho 8, 2021.

  1. Stack

    Stack Membro Participativo


    The variable name '@LockState' has already been declared. Variable names must be unique within a query batch or stored procedure.

    When I execute this code below, above error comes on my sql parameters on second @LockState.

    private void btn_lock2_Click(object sender, EventArgs e)
    {
    rwd.command = new SqlCommand();
    rwd.command.Connection = rwd.connection;

    try
    {
    if ((txt2.Text == "")| (txt_desc2.Text == ""))
    appMessages.unCompleteFields();
    else
    {
    long from = long.Parse(this.txt2.Text);
    long to = long.Parse(this.txt3.Text);
    if (from <= to)
    {
    for (long counter = from; counter <= to; counter++)
    {
    string upd = "update card set LockState=@lockstate,
    card_descr=@card_descr where [cardNumber] = N'{0}'";
    rwd.command.CommandText = upd;
    rwd.command.Parameters.Add(new SqlParameter("@LockState",
    SqlDbType.NVarChar)).Value =1;
    rwd.command.Parameters.Add(new SqlParameter("@card_descr",
    SqlDbType.NVarChar)).Value = txt_desc2.Text;
    rwd.connection.Open();
    rwd.command.ExecuteScalar();
    rwd.connection.Close();
    }
    appMessages.successfulyUpdated();
    }
    else
    {
    appMessages.unsuccessfulyUpdated();
    }
    this.txt1.Text = "";
    this.txt2.Text = "";
    }
    }
    catch (Exception exp) { throw exp; }
    }
    }

    Continue reading...

Compartilhe esta Página

Para os pais de Plantão algumas dicas