0

There are some topics related to my topic however I couldn't solve my problems with them.

Each time I get same messages.

procedure :

USE [onmuhasebe]
GO
/****** Object:  StoredProcedure [dbo].[stok]    Script Date: 5.01.2017 15:34:45 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[stok]
( @cari NVARCHAR(50),
  @urun NVARCHAR(50),
  @miktar INT

 )
 AS
 BEGIN
 update stok_giris SET miktar= miktar- @miktar WHERE cari=@cari and urun=@urun

 END

I need the subtraction here.

try
{
    baglanti.Open();
    //int miktar = Int32.Parse(textBox4.Text);
    //int miktar = Convert.ToInt32(textBox4.Text);
    int miktar = Convert.ToInt32(textBox4.Text.Trim());


    SqlCommand mySqlCommand = new SqlCommand("stok", baglanti);
    mySqlCommand.CommandType = CommandType.StoredProcedure;


    mySqlCommand.Parameters.AddWithValue("@cari", comboBox2.SelectedItem.ToString());


    mySqlCommand.Parameters.AddWithValue("@urun", comboBox5.SelectedItem.ToString());

    mySqlCommand.Parameters.Add("@miktar", SqlDbType.Int);
    mySqlCommand.Parameters.AddWithValue("@miktar", miktar);

    mySqlCommand.ExecuteNonQuery();

}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

1 Answer 1

4

By using Add and AddWithValue you are adding four parameters to the command even though both are @miktar But the procedure accepting three values; you should give the third parameter like this:

mySqlCommand.Parameters.Add("@miktar", SqlDbType.Int).Value = miktar;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.