Passing Parameter in C# to SQL Stored Procedure Archives - Tech Insights https://reactconf.org/category/passing-parameter-in-c-to-sql-stored-procedure/ Unveiling Tomorrow's Tech Today, Where Innovation Meets Insight Sun, 08 Jun 2014 18:06:00 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 https://i0.wp.com/reactconf.org/wp-content/uploads/2023/11/cropped-reactconf.png?fit=32%2C32&ssl=1 Passing Parameter in C# to SQL Stored Procedure Archives - Tech Insights https://reactconf.org/category/passing-parameter-in-c-to-sql-stored-procedure/ 32 32 230003556 Passing Parameter in C# to SQL Stored Procedure https://reactconf.org/passing-parameter-in-c-to-sql-stored/ https://reactconf.org/passing-parameter-in-c-to-sql-stored/#respond Sun, 08 Jun 2014 18:06:00 +0000 http://www.sqlneed.com/2014/06/08/passing-parameter-in-c-to-sql-stored-procedure/ Write a SQL Server Stored procedure with Two Parameter. This SQL Server Stored Procedure insert the User Information like Username and Password, you can change as per your requirement. SET …

The post Passing Parameter in C# to SQL Stored Procedure appeared first on Tech Insights.

]]>
Write a SQL Server Stored procedure with Two Parameter. This SQL Server Stored Procedure insert the User Information like Username and Password, you can change as per your requirement.
SET ANSI_NULLSON
GO
SET QUOTED_IDENTIFIERON
GO
— =============================================
— Author:         <Ahmed>
— =============================================
CREATE PROCEDUREInsertUsers
(@UserName varchar(25),@UserPWD varchar(20))
      
AS
BEGIN
     — SET NOCOUNT ON added to prevent extra result sets from
     — interfering with SELECT statements.
     SET NOCOUNT ON;
    — Insert statements for procedure here
     INSERT INTO Lib_Users(User_Name,User_Password)
     VALUES(@USERNAME,@USERPWD);   
END
GO
Now this C# program passing parameter to stored procdure.
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Data.SqlClient;
namespacePassingParameterinCSharptoSqlserver
{
    public partial class Form1 : Form
    {
        stringcon = “Data Source=ServerName;Initial Catalog=DataBaseName;Integrated Security=True”;
  publicForm1()
  {
  InitializeComponent();
  }
  privatevoid button1_Click(objectsender, EventArgs e)
  { 

SqlConnection cnn =newSqlConnection(con);

  try
 {
  cnn.Open();
  SqlCommandSqlCmd = new SqlCommand(“InsertUsers”,cnn);
  SqlCmd.CommandType = CommandType.StoredProcedure;
              
              //passing parameter to stored procedure
             
                SqlCmd.Parameters.AddWithValue(“@USERNAME”, textBox2.Text);
                SqlCmd.Parameters.AddWithValue(“@USERPWD”, textBox3.Text);
                SqlCmd.ExecuteNonQuery();
                MessageBox.Show(“Record Inserted Successfully….”);
                cnn.Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                cnn.Close();
             }
        }
        privatevoid button2_Click(objectsender, EventArgs e)
        {
            this.Close();
        }
    }
}

The post Passing Parameter in C# to SQL Stored Procedure appeared first on Tech Insights.

]]>
https://reactconf.org/passing-parameter-in-c-to-sql-stored/feed/ 0 2240