{"id":31,"date":"2009-01-14T02:12:00","date_gmt":"1970-01-01T00:00:00","guid":{"rendered":"http:\/\/www.yazilimmutfagi.com\/?p=31"},"modified":"2009-01-14T02:12:00","modified_gmt":"1970-01-01T00:00:00","slug":"csharp-ta-stored-procedure-kullanmak","status":"publish","type":"post","link":"https:\/\/www.yazilimmutfagi.com\/index.php\/2009\/01\/14\/csharp-ta-stored-procedure-kullanmak\/","title":{"rendered":"CSharp ta Stored Procedure Kullanmak"},"content":{"rendered":"<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><strong style=\"\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">C# ta Stored Procedure Kullanmak<\/span><\/span><\/strong><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: small; font-family: Calibri;\">Tekrar merhaba. &Ouml;nceki makalemde stored procedureler hakkinda bir giris bilgisi vermistim ve genel olarak nasil yazildigina dair &ouml;rnekler yapmistik. Bu makalemde stored procedurelerin c#&rsquo;ta kullanilmasi ile ilgili biraz bilgi verecegim. <span style=\"\">&nbsp;<\/span>&Ouml;nceki makaleye <\/span><a href=\"..\/MakaleOku.aspx?Makale=Stored+Procedurelere+Giri%c5%9f&amp;MakaleKey=f05b632a-eadf-4d38-8afb-0d3462a18d45\"><span style=\"font-size: small; font-family: Calibri;\">buradan<\/span><\/a><span style=\"font-size: small; font-family: Calibri;\"> ulasabilirsiniz.<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">Bildiginiz gibi normal bir c# uygulamasi yaptiginizda sql&rsquo;le baglanti kurmak i&ccedil;in bir SqlConnection nesnesi, bir SqlCommand nesnesi ve duruma g&ouml;re SqlDataReader veya AqlDataAdapter nesneleri kullaniriz. Bunda da ayni nesneleri kullanacagiz. Fakat tek farklilik sqlcommand nesnesinde olacak. Daha &ouml;nceki makalemizde kullandigimiz;<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><a href='www.yazilimmutfagi.com'>.<\/a><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: rgb(43, 145, 175); font-family: &quot;Courier New&quot;;\">SqlCommand<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> mycommand = <span style=\"color: blue;\">new<\/span> <span style=\"color: rgb(43, 145, 175);\">SqlCommand<\/span>();<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\">mycommand.CommandType = <span style=\"color: rgb(43, 145, 175);\">CommandType<\/span>.Text;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">satirini <span style=\"\">&nbsp;<\/span><\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: rgb(43, 145, 175); font-family: &quot;Courier New&quot;;\">SqlCommand<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> mycommand = <span style=\"color: blue;\">new<\/span> <span style=\"color: rgb(43, 145, 175);\">SqlCommand<\/span>();<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\">mycommand.CommandType = <span style=\"color: rgb(43, 145, 175);\">CommandType<\/span>.StoredProcedure;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">olarak degistiriyoruz. <\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: small; font-family: Calibri;\">Bir de; <\/span><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\">mycommand.CommandText <\/span><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">= kismina &ccedil;ift tirnak i&ccedil;inde storedprocedure&rsquo;&uuml;m&uuml;z&uuml;n adini yaziyoruz. <span style=\"\">&nbsp;<\/span>&Ouml;rnegin:<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\">mycommand.CommandText = <span style=\"color: rgb(163, 21, 21);\">&quot;sp_Deneme_Ekle&quot;<\/span>;<\/span><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\"> <\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">Daha sonra da procedure&rsquo;&uuml;m&uuml;z&uuml;n aldigi nesneleri g&ouml;nderiyoruz. Simdi bunu daha a&ccedil;iklayici anlatabilmek i&ccedil;in bir &ouml;rnek yapmak istiyorum. &Ouml;ncelikle bir procedure olusturalim:<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">CREATE<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> <span style=\"color: blue;\">PROCEDURE<\/span> sp_Deneme_Ekle<span style=\"color: blue;\"> <\/span><span style=\"color: gray;\">(<\/span>@AD <span style=\"color: blue;\">NVARCHAR<\/span><span style=\"color: gray;\">(<\/span>20<span style=\"color: gray;\">),<\/span>@SOYAD <span style=\"color: blue;\">NVARCHAR<\/span><span style=\"color: gray;\">(<\/span>20<span style=\"color: gray;\">))<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">AS<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">INSERT<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> <span style=\"color: blue;\">INTO<\/span> DENEME_TABLO<span style=\"color: gray;\">(<\/span>AD<span style=\"color: gray;\">,<\/span>SOYAD<span style=\"color: gray;\">)<\/span> <span style=\"color: blue;\">VALUES<\/span><span style=\"color: gray;\">(<\/span>@AD<span style=\"color: gray;\">,<\/span>@SOYAD<span style=\"color: gray;\">)<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">GO<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: small; font-family: Calibri;\">G&ouml;r&uuml;ld&uuml;g&uuml; gibi procedure&rsquo;&uuml;m&uuml;z iki tane deger aliyor (ad ve soyad) ve bunlari DENEME_TABLO isimli tablonun AD ve SOYAD s&uuml;tunlarina ekliyor. Simdiki asama C#&rsquo;ta bu storedprocdure&rsquo;&uuml; kullanmak i&ccedil;in gerekli baglantilari yapmak. Bu baglantilari da bir metot i&ccedil;inde kullanmak istiyorum.<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">public<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> <span style=\"color: blue;\">void<\/span> KAYIT(<span style=\"color: blue;\">string<\/span> ad, <span style=\"color: blue;\">string<\/span> soyad)<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">{<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: rgb(43, 145, 175);\">SqlConnection<\/span> mycon = <span style=\"color: blue;\">new<\/span> <span style=\"color: rgb(43, 145, 175);\">SqlConnection<\/span>();<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: rgb(43, 145, 175);\">SqlCommand<\/span> mycommand = <span style=\"color: blue;\">new<\/span> <span style=\"color: rgb(43, 145, 175);\">SqlCommand<\/span>();<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Connection = mycon;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycon.ConnectionString = <span style=\"color: rgb(163, 21, 21);\">&quot;&quot;<\/span>;<span style=\"color: green;\">\/\/connectionstring buraya yazilmalidir<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycon.Open();<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.CommandText = <span style=\"color: rgb(163, 21, 21);\">&quot;sp_Deneme_Ekle&quot;<\/span>;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.CommandType = <span style=\"color: rgb(43, 145, 175);\">CommandType<\/span>.StoredProcedure;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Parameters.Add(<span style=\"color: rgb(163, 21, 21);\">&quot;@AD&quot;<\/span>, <span style=\"color: rgb(43, 145, 175);\">SqlDbType<\/span>.NVarChar, 50);<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Parameters[<span style=\"color: rgb(163, 21, 21);\">&quot;@AD&quot;<\/span>].Value = ad;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Parameters.Add(<span style=\"color: rgb(163, 21, 21);\">&quot;@SOYAD&quot;<\/span>, <span style=\"color: rgb(43, 145, 175);\">SqlDbType<\/span>.NVarChar, 50);<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Parameters[<span style=\"color: rgb(163, 21, 21);\">&quot;@SOYAD&quot;<\/span>].Value = soyad;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.ExecuteNonQuery();<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycon.Close();<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\">}<\/span><span style=\"font-size: small; font-family: Calibri;\"> <\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">G&ouml;rd&uuml;g&uuml;n&uuml;z gibi KAYIT metodu veritabanindaki sp_Deneme_Ekle isimli procedure&rsquo;&uuml; kullaniyor, ad ve soyad isminde iki tane string parametre aliyor ve geriye deger d&ouml;nd&uuml;rm&uuml;yor. <\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt; text-indent: 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">mycommand.Parameters.Add(<span style=\"color: rgb(163, 21, 21);\">&quot;@AD&quot;<\/span>, <span style=\"color: rgb(43, 145, 175);\">SqlDbType<\/span>.NVarChar, 50);<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\">mycommand.Parameters[<span style=\"color: rgb(163, 21, 21);\">&quot;@AD&quot;<\/span>].Value = ad;<\/span><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\"> <\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: small; font-family: Calibri;\">satirlari procedure&rsquo;&uuml;m&uuml;ze parametre g&ouml;ndermek i&ccedil;in kullanilir. <\/span><span style=\"font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%; font-family: &quot;Courier New&quot;;\">SqlDbType<\/span><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\"> yazdiktan sonra nokta koyunca sql&rsquo;deki parametre tiplerini hepsi g&ouml;r&uuml;nmektedir(int,datetime gibi). Simdi burada dikkat etmemiz gereken bir ka&ccedil; husus var. <\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 36pt; text-indent: -18pt;\" class=\"MsoListParagraphCxSpFirst\"><span style=\"\"><span style=\"\"><span style=\"font-size: small; font-family: Calibri;\">1.<\/span><span style=\"font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">StoredProcedure&rsquo;de nesneleri hangi siraya g&ouml;re yazdiysak (yani bizim &ouml;rnek i&ccedil;in &ouml;nce ad sonra soyad) C#&rsquo;tan da o siraya g&ouml;re tanitmaliyiz. Yani &ouml;nce soyad sonra ad parametrelerini g&ouml;nderemeyiz.<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 36pt; text-indent: -18pt;\" class=\"MsoListParagraphCxSpMiddle\"><span style=\"\"><span style=\"\"><span style=\"font-size: small; font-family: Calibri;\">2.<\/span><span style=\"font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">Veritabaninda parametrelerin &ouml;n&uuml;ne @ isareti koydugumuz i&ccedil;in C#&rsquo;ta da<span style=\"\">&nbsp; <\/span>parametreleri g&ouml;ndermek i&ccedil;in<span style=\"\">&nbsp; <\/span>@ isareti kullanmamiz gerekir: &ldquo;@AD&quot;gibi<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt 36pt; text-indent: -18pt;\" class=\"MsoListParagraphCxSpLast\"><span style=\"\"><span style=\"\"><span style=\"font-size: small; font-family: Calibri;\">3.<\/span><span style=\"font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">Parametrelerdeki b&uuml;y&uuml;k k&uuml;&ccedil;&uuml;k harf farkliligina dikkat etmeliyiz. Yani procedure&rsquo;de @AD olarak tanittigimiz parametreyi C#&rsquo;ta @ad olarak g&ouml;steremeyiz.<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\"><span style=\"\">&nbsp;<\/span>Su ana kadarki kisimda veritabanimizda olusturdugumuz bir procedure&rsquo;e nasil ulasacagimiz g&ouml;rd&uuml;k. Simdi eger bu procedure deger d&ouml;nd&uuml;r&uuml;yorsa nasil kullanacagiz? &Ouml;nceki makalemde stored procedure&rsquo;lerin nasil deger d&ouml;nd&uuml;rd&uuml;g&uuml;n&uuml; ve ni&ccedil;in buna ihtiya&ccedil; duyuldugunu anlatmistim. Simdi bununla ilgili bir &ouml;rnek yapalim: <\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">&Ouml;nce procedure&rsquo;&uuml;m&uuml;z&uuml; biraz degistirelim. Ayni ad ve soyadda baska biri varsa kayit yapmasin ve geriye 0 degeri d&ouml;nd&uuml;rs&uuml;n. Eger yoksa kayit yapsin ve bize 1 degeri d&ouml;nd&uuml;rs&uuml;n.<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">CREATE<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> <span style=\"color: blue;\">PROCEDURE<\/span> sp_Deneme_Ekle<span style=\"color: blue;\"> <\/span><span style=\"color: gray;\">(<\/span>@AD <span style=\"color: blue;\">NVARCHAR<\/span><span style=\"color: gray;\">(<\/span>20<span style=\"color: gray;\">),<\/span>@SOYAD <span style=\"color: blue;\">NVARCHAR<\/span><span style=\"color: gray;\">(<\/span>20<span style=\"color: gray;\">))<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">AS<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">Declare<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> @kayitkontrol <span style=\"color: blue;\">int<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">Declare<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> @SONUC <span style=\"color: blue;\">int<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">Set<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> @kayitkontrol<span style=\"color: gray;\">=<\/span><span style=\"color: blue;\">select<\/span> <span style=\"color: fuchsia;\">count<\/span><span style=\"color: gray;\">(*)<\/span> <span style=\"color: blue;\">from<\/span> DENEME_TABLO <span style=\"color: blue;\">where<\/span> AD<span style=\"color: gray;\">=<\/span>@AD <span style=\"color: gray;\">and<\/span> SOYAD <span style=\"color: gray;\">=<\/span> @SOYAD<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">if<\/span><span style=\"font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;;\">(<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">@kayitkontrol <span style=\"color: gray;\">=<\/span> 0<span style=\"color: gray;\">)<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">begin<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">INSERT<\/span> <span style=\"color: blue;\">INTO<\/span> DENEME_TABLO<span style=\"color: gray;\">(<\/span>AD<span style=\"color: gray;\">,<\/span>SOYAD<span style=\"color: gray;\">)<\/span> <span style=\"color: blue;\">VALUES<\/span><span style=\"color: gray;\">(<\/span>@AD<span style=\"color: gray;\">,<\/span>@SOYAD<span style=\"color: gray;\">)<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">set<\/span> @SONUC <span style=\"color: gray;\">=<\/span> 1<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">end<\/span> <\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">else<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">begin<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">set<\/span> @SONUC <span style=\"color: gray;\">=<\/span>0<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">end<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">return<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> @SONUC<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">GO<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">Siradaki asama C#&rsquo;ta bu procedure&rsquo;&uuml; kullanmak. &Ouml;nceki &ouml;rnekteki metotu bu procedure&rsquo;e uygun olarak degistirecegiz ve d&ouml;n&uuml;s degerini int olarak belirleyecegiz. <\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: small; font-family: Calibri;\">&nbsp;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;\">public<\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"> <span style=\"color: blue;\">int<\/span> KAYIT(<span style=\"color: blue;\">string<\/span> ad, <span style=\"color: blue;\">string<\/span> soyad)<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\">{<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">int<\/span> sonuc;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: rgb(43, 145, 175);\">SqlConnection<\/span> mycon = <span style=\"color: blue;\">new<\/span> <span style=\"color: rgb(43, 145, 175);\">SqlConnection<\/span>();<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: rgb(43, 145, 175);\">SqlCommand<\/span> mycommand = <span style=\"color: blue;\">new<\/span> <span style=\"color: rgb(43, 145, 175);\">SqlCommand<\/span>();<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Connection = mycon;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycon.ConnectionString = <span style=\"color: rgb(163, 21, 21);\">&quot;&quot;<\/span>;<span style=\"color: green;\">\/\/connectionstring buraya yazilmalidir<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycon.Open();<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.CommandText = <span style=\"color: rgb(163, 21, 21);\">&quot;DENEME_EKLE&quot;<\/span>;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.CommandType = <span style=\"color: rgb(43, 145, 175);\">CommandType<\/span>.StoredProcedure;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Parameters.Add(<span style=\"color: rgb(163, 21, 21);\">&quot;@AD&quot;<\/span>,<span style=\"color: rgb(43, 145, 175);\">SqlDbType<\/span>.NVarChar, 50);<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Parameters[<span style=\"color: rgb(163, 21, 21);\">&quot;@AD&quot;<\/span>].Value = ad;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Parameters.Add(<span style=\"color: rgb(163, 21, 21);\">&quot;@SOYAD&quot;<\/span>, <span style=\"color: rgb(43, 145, 175);\">SqlDbType<\/span>.NVarChar, 50);<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Parameters[<span style=\"color: rgb(163, 21, 21);\">&quot;@SOYAD&quot;<\/span>].Value = soyad;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Parameters.Add(<span style=\"color: rgb(163, 21, 21);\">&quot;@SONUC&quot;<\/span>, <span style=\"color: rgb(43, 145, 175);\">SqlDbType<\/span>.Int);<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Parameters[<span style=\"color: rgb(163, 21, 21);\">&quot;@SONUC&quot;<\/span>].Direction = <span style=\"color: rgb(43, 145, 175);\">ParameterDirection<\/span>.ReturnValue;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.ExecuteNonQuery();<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>sonuc = <span style=\"color: rgb(43, 145, 175);\">Convert<\/span>.ToInt32(mycommand.Parameters[<span style=\"color: rgb(163, 21, 21);\">&quot;@KONTROL&quot;<\/span>].Value);<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycon.Close();<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt 35.4pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue;\">return<\/span> sonuc;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\">}<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: small; font-family: Calibri;\">g&ouml;r&uuml;ld&uuml;g&uuml; &uuml;zere sadece <\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><a href='www.yazilimmutfagi.com'>.<\/a><\/p>\n<p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Parameters.Add(<span style=\"color: rgb(163, 21, 21);\">&quot;@SONUC&quot;<\/span>, <span style=\"color: rgb(43, 145, 175);\">SqlDbType<\/span>.Int);<\/span><\/p>\n<p style=\"margin: 0cm 0cm 0pt; line-height: normal;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"\">&nbsp;&nbsp;&nbsp; <\/span>mycommand.Parameters[<span style=\"color: rgb(163, 21, 21);\">&quot;@SONUC&quot;<\/span>].Direction = <span style=\"color: rgb(43, 145, 175);\">ParameterDirection<\/span>.ReturnValue;<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">ve<\/span><\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt; text-indent: 35.4pt;\" class=\"MsoNormal\"><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\">sonuc = <span style=\"color: rgb(43, 145, 175);\">Convert<\/span>.ToInt32(mycommand.Parameters[<span style=\"color: rgb(163, 21, 21);\">&quot;@<\/span><\/span><span style=\"font-size: 10pt; font-family: &quot;Courier New&quot;;\"><span style=\"color: rgb(163, 21, 21);\">SONUC<\/span><\/span><span style=\"font-size: 10pt; line-height: 115%; font-family: &quot;Courier New&quot;;\"><span style=\"color: rgb(163, 21, 21);\">&quot;<\/span>].Value);<\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: small; font-family: Calibri;\">satirlarini ekledik ve geri d&ouml;n&uuml;s degerini almis olduk. <\/span><\/p>\n<p style=\"margin: 0cm 0cm 10pt;\" class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">Umarim bu makale bilgilendirici olmustur. Bir sonraki makalede g&ouml;r&uuml;smek &uuml;zere.<\/span><\/span><\/p>","protected":false},"excerpt":{"rendered":"<p>Tekrar merhaba. &#214;nceki makalemde stored procedureler hakkinda bir giris bilgisi vermistim ve genel olarak nasil yazildigina dair &#246;rnekler yapmistik. Bu makalemde stored procedurelerin c#\u2019ta kullanilmasi ile ilgili biraz bilgi verecegim.<\/p>\n","protected":false},"author":535,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[422],"tags":[4247,4987,5603,5272,4530,6125,5809,4200],"_links":{"self":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts\/31"}],"collection":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/users\/535"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":0,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}