Stored Procedure with parameter in C# with Sql Server for Insertion
Consider Table name:sampletable
field 
username nvarchar(50)
mark1 int
Write it in Stored Procedure [if you create table first time, Then it automatically changed to alter]Procedure name-InsertUser
ALTER PROCEDURE [dbo].[InsertUser] 
(
@username varchar(50),
@mark1 int
) 
AS
INSERT INTO sampletable VALUES(@username, @mark1)
Coding in C#
protected void Button1_Click(object sender, EventArgs e)
    {
        string username=(TextBox1.Text);
        string mark=(TextBox2.Text);
        SqlConnection myConnection = new SqlConnection("user id=userid;" +    "password=pwd;" + "Data source=localhost;" + "Integrated security=true;" +                              "database=sample;");
        SqlCommand myCommand = new SqlCommand("InsertUser", myConnection);
        myCommand.CommandType = CommandType.StoredProcedure;
        myCommand.Parameters.Add("@username", SqlDbType.VarChar).Value = username;
        myCommand.Parameters.Add("@mark1", SqlDbType.Int).Value = mark;
        myConnection.Open();
        int rows = myCommand.ExecuteNonQuery();
        myConnection.Close();
    }
Dotnet, DotnetCore, Azure, C#,VB.net, Sql Server, WCF, MVC ,Linq, Javascript and Jquery
Subscribe to:
Post Comments (Atom)
Implementing OAuth validation in a Web API
I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...
- 
ViewBag, ViewData, TempData and View State in MVC ASP.NET MVC offers us three options ViewData, ViewBag and TempData for passing data from...
 - 
View in Sql Server 2008 Creates a virtual table whose contents (columns and rows) are defined by a query. Use this statement to create a vie...
 - 
// Export Datatable to Excel in C# Windows application using System; using System.Data; using System.IO; using System.Windows.Forms; ...
 
No comments:
Post a Comment
Comments Welcome