Note that there are some explanatory texts on larger screens.

plurals
  1. POExecute SQL stored procedure with textBox value error in C#
    text
    copied!<p>I am trying to make a program that stores data form to Sql. I made this part initially by making the insert query from my form and worked perfectly, but I wanted to make my code more robust and the program faster using sql stored procedures. The procedure code from my SQL is the following ( this is the code from the alter procedure option):</p> <pre><code>USE [DBStudent] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[shto_student_proc] @result int output, @emer_std [nvarchar](50), @atesi_std [nvarchar](50) , @mbiemer_std [nvarchar](50) , @datelindje_std [nvarchar](50) , @dok_std [nvarchar](50) , @nrdok_std [nvarchar](50), @adresa_std [nvarchar](50) , @telefon_std [nvarchar](50), @kategori_std [nvarchar](50) , @aktiv_std [nvarchar](2) , @email_std [nvarchar](50) , @menaxher_std nvarchar(2) AS BEGIN SET NOCOUNT ON; SELECT @result=COUNT(*) from dbo.student WHERE st_emer=@emer_std and st_mbiemer=@mbiemer_std and st_datelindje=@datelindje_std and st_dok=@dok_std -- check if record exists IF @result=0 BEGIN INSERT INTO student ([st_emer],[st_atesi],[st_mbiemer],[st_datelindje],[st_dok],[st_nrdok],[st_adresa],[st_telefon],[st_kategoria],st_aktiv,[st_email],st_menaxher) VALUES (@emer_std,@atesi_std,@mbiemer_std ,@datelindje_std,@dok_std,@nrdok_std ,@adresa_std,@telefon_std,@kategori_std,@aktiv_std,@email_std,@menaxher_std ) END END GO </code></pre> <p>And this is the C# code of the button:</p> <pre><code>private void save_btn_Click(object sender, EventArgs e) { string date=dtl_dtp.Value.ToString("yyyyMMdd"); string komand_procedura = " EXECUTE dbo.shto_student_proc @emer_std,@atesi_std,@mbiemer_std ," + "@datelindje_std,@dok_std,@nrdok_std ,@adresa_std,@telefon_std,@kategori_std,@aktiv_std,@email_std,@menaxher_std "; SqlCommand cmd = new SqlCommand(komand_procedura,con1); cmd.Parameters.Add(new SqlParameter("@emer_std",SqlDbType.NVarChar,50)); cmd.Parameters["@emer_std"].Value = emer_tb.Text; cmd.Parameters.Add(new SqlParameter("@atesi_std",SqlDbType.NVarChar,50)); cmd.Parameters["@atesi_std"].Value = atesi_tb.Text; cmd.Parameters.Add(new SqlParameter("@mbiemer_std",SqlDbType.NVarChar,50)); cmd.Parameters["@mbiemer_std"].Value = mbiemer_tb.Text; cmd.Parameters.Add(new SqlParameter("@datelindje_std",SqlDbType.NVarChar,50)); cmd.Parameters["@datelindje_std"].Value = date; cmd.Parameters.Add(new SqlParameter("@dok_std",SqlDbType.NVarChar,50)); cmd.Parameters["@dok_std"].Value = dok_cmb.Text; cmd.Parameters.Add(new SqlParameter("@nrdok_std",SqlDbType.NVarChar,50)); cmd.Parameters["@nrdok_std"].Value = nrdok_tb.Text; cmd.Parameters.Add(new SqlParameter("@adresa_std",SqlDbType.NVarChar,50)); cmd.Parameters["@adresa_std"].Value = textBox5.Text; cmd.Parameters.Add(new SqlParameter("@telefon_std",SqlDbType.NVarChar,50)); cmd.Parameters["@telefon_std"].Value = textBox6.Text; cmd.Parameters.Add(new SqlParameter("@kategori_std",SqlDbType.NVarChar,50)); cmd.Parameters["@kategori_std"].Value = comboBox1.Text; cmd.Parameters.Add(new SqlParameter("@aktiv_std",SqlDbType.NVarChar,2)); cmd.Parameters["@aktiv_std"].Value="PO"; cmd.Parameters.Add(new SqlParameter("@email_std",SqlDbType.NVarChar,50)); cmd.Parameters["@email_std"].Value = textBox7.Text; //MessageBox.Show(cmd.Parameters["@email_std"].Value.ToString()); cmd.Parameters.Add("@menaxher_std", SqlDbType.NVarChar, 2); cmd.Parameters["@menaxher_std"].Value="JO"; SqlParameter output = cmd.Parameters.Add("@result",SqlDbType.Int); output.Direction = ParameterDirection.ReturnValue; con1.Open(); try { cmd.ExecuteNonQuery(); MessageBox.Show("Added "+output.ToString()+" rows"); } catch (SqlException ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } con1.Close(); } </code></pre> <p>I am having this error:</p> <blockquote> <p>Procedure or function 'shto_student_proc' expects parameter '@menaxher_std', which was not supplied.</p> </blockquote> <p>I have tried with textboxes to check if the values were added to the parameter and they were. Can anyone help me?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload