Reputation: 11
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);
}
Upvotes: 0
Views: 143
Reputation: 29026
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;
Upvotes: 4