The parameterized query expects the parameter '@Id', which was not supplied.

  • info.feedback98

    SSC Veteran

    Points: 233

    Hi,I am writing a software I use method (parameters.add) but when I am adding data to a database I get the error below:

    The parameterized query expects the parameter '@Id', which was not supplied.

    I put c# code and stored procedure code below:

    private void btnSave_Click(object sender, EventArgs e)

    {

    string cs = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TranscactionAccountNumber;Data Source=DESKTOP-5DJFFQP";

    string name = txtName.Text;

    int shomarepeygiri = int.Parse(txtShomarePeygiri.Text);

    string date = dtpDate.Shamsi;

    decimal mablagh = decimal.Parse(txtMablagh.Text);

    string comment = txtComment.Text;

    using (cn = new SqlConnection(cs))

    using (cmd = new SqlCommand("InsertTransaction", cn))

    {

    cmd.Parameters.Add("@Id",SqlDbType.Int);

    cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 100).Value = name;

    cmd.Parameters.Add("@ShomarePeygiri", SqlDbType.Int).Value = shomarepeygiri;

    cmd.Parameters.Add("@Mablagh", SqlDbType.Decimal).Value = mablagh;

    cmd.Parameters.Add("@Comment", SqlDbType.NVarChar).Value = comment;

    cmd.Parameters.Add("@Date", SqlDbType.VarChar).Value = date;

    if (cn.State == ConnectionState.Closed)

    cn.Open();

    cmd.ExecuteNonQuery();

    MessageBox.Show("Transaction Added Successfully..", "Register Transaction", MessageBoxButtons.OK, MessageBoxIcon.Information);

    }

    }

    Create procedure InsertTransaction

    (

    @id int,

    @Name nvarchar(100),

    @ShomarePeygiri int,

    @Mablagh decimal(18, 0),

    @Comment nvarchar(MAX),

    @PersianDate varchar(10)

    )

    AS

    Insert Into TransactionTable(id,[Name],ShomarePeygiri,Mablagh,Comment,PersianDate)

    values (@id,@Name,@ShomarePeygiri,@Mablagh,@Comment,@PersianDate)

  • Igor Micev

    SSC-Dedicated

    Points: 33108

    Expects the parameter '@Id', which was not supplied:

    cmd.Parameters.Add("@Id",SqlDbType.Int);

    but here you're supplying the @Name parameter

    cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 100).Value = name;

    Igor Micev,
    My blog: www.igormicev.com

  • HanShi

    SSC-Dedicated

    Points: 33142

    I'm not familiar wirth C#, but shouldn't you pass a value for the ID parameter (see bold part below)?

    <snip>

    cmd.Parameters.Add("@Id",SqlDbType.Int).Value = Id;

    cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 100).Value = name;

    <snip>

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • asadqadri66

    Grasshopper

    Points: 11

    Hi i'm suffering from this error in SQL Server 2012 Please help me. The error isHi i'm suffering from this error in SQL Server 2012 Please help me. The error is "Procedure or function 'splogin' expects parameter '@memberid', which was not supplied."

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply