Using Stored Procedures with ASP.NET with parameter in c# and SQL - Microsoft ASP Solutions
- Using Stored Procedures with ASP.NET
- SQL Server Stored Procedure with C#.Net
- Call a stored procedure with parameter in c# - Microsoft ASP Solutions
- c# .net How to use a stored procedure? - Microsoft ASP Solutions
- Step by Step to use Stored Procedures in Asp.Net C# - Microsoft ASP Solutions
- how to use stored procedure in asp.net c# with example
- create stored procedure in c#
- C# Stored Procedure with Parameter - Microsoft ASP Solutions
- how to call stored procedure in c# | stored procedure in c#
Design ASPX Page Code Below
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataTable.aspx.cs" Inherits="DataTable" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Microsoft ASP Solutions</title>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.6.1/css/buttons.dataTables.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" />
</head>
<body>
<form id="form1" runat="server">
<br /><br />
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="form-inline">
<label>OrderNo</label>
<asp:TextBox runat="server" ID="txtOrdno" CssClass="form-control" required></asp:TextBox>
<label>ItemCode</label>
<asp:TextBox runat="server" ID="txtItemcode" CssClass="form-control" required></asp:TextBox>
<label>ProdCode</label>
<asp:TextBox runat="server" ID="txtProdcode" CssClass="form-control" required></asp:TextBox>
<label>EntDate</label>
<asp:TextBox runat="server" ID="txtEntDt" CssClass="form-control" required></asp:TextBox>
<asp:Button runat="server" ID="btnSubmit" Text="Save" OnClick="btnSubmit_Click" CssClass="btn btn-primary" />
</div>
</div>
</div>
</div>
<br />
<div class="container">
<div class="row">
<div class="col-md-12">
<table cellpadding="0" cellspacing="0" border="0" class="table table-bordered table-condensed compact display nowrap table-hover" id="example">
<thead>
<tr>
<th style="width: 5%;">RowId
</th>
<th>OrderNo
</th>
<th>ItemCode
</th>
<th>ProdCode
</th>
<th>EntDate
</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
SQL Store Procedure Creare Code Below
CREATE PROCEDURE CurdOp
-- Add the parameters for the stored procedure here
@Orderno varchar(50),
@ItemCode varchar(50),
@ProdCode varchar(50),
@EntDate datetime,
@status varchar(10)
AS
Begin
Set Nocount On;
--insert record
if @status='Insert'
begin
insert into Cb_OrderTrnSub(Order_No,ITMCode,ProdCode,EntDate) values(@Orderno,@ItemCode,@ProdCode,@EntDate)
end
--update record
if @status='Update'
begin
update Cb_OrderTrnSub set ITMCode=@ItemCode,ProdCode=@ProdCode,EntDate=@EntDate where Order_No=@Orderno
end
--delete record
if @status='Delete'
begin
delete from Cb_OrderTrnSub where Order_No=@Orderno
end
SET NOCOUNT OFF
end
RETURN 0
ASPX.cs Page Code To Insert Data in SQL With Parameter in Store Procedure
protected void btnSubmit_Click(object sender, EventArgs e)
{
Prodecure("Insert");
}
public void Prodecure(string status)
{
con.Open();
SqlCommand cmd = new SqlCommand("CurdOp", con);
cmd.CommandType = CommandType.StoredProcedure;
if (status == "Insert")
{
cmd.Parameters.AddWithValue("@status",status);
cmd.Parameters.AddWithValue("@Orderno", txtOrdno.Text);
cmd.Parameters.AddWithValue("@ItemCode", txtItemcode.Text);
cmd.Parameters.AddWithValue("@ProdCode", txtProdcode.Text);
cmd.Parameters.AddWithValue("@EntDate", txtEntDt.Text);
}
cmd.ExecuteNonQuery();
con.Close();
}
No comments