Click here to Skip to main content
15,915,019 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guy's ...
i want use stored procedure in 3-Tier for CRUD !

this procedure :

C#
USE [RahgoshafanDB]GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE Category_Insert
@Category NVARCHAR(MAX),
@Toz NVARCHAR(MAX)
AS
BEGIN
INSERT INTO Category(Category, Toz)
VALUES (@Category, @Toz)
END


this data access layer :

C#
using System;using System.Data;
using System.Data.SqlClient;
namespace DAL
{
public class Category_Dal
{
SqlConnection SqlCon = new SqlConnection("Data Source=.;Initial Catalog=RahgoshafanDB;Integrated Security=True");
int id;
public void Category_Insert()
{
try
{
SqlCommand cmd = new SqlCommand("Category_Insert", SqlCon);
cmd.CommandType = CommandType.StoredProcedure;
SqlCon.Open();
cmd.ExecuteNonQuery();
}
finally
{
if (SqlCon.State != ConnectionState.Closed)
SqlCon.Close();
}
}
}
}


butt now ... i not know write in BLL and Button_Insert
please help !
Posted
Comments
Maciej Los 15-Apr-15 13:22pm    
Not sure what you're asking for... All you need to do is to call Category_Insert procedure...
Sergey Alexandrovich Kryukov 15-Apr-15 14:25pm    
How "3-tier" can possibly be related to stored procedure? A stored procedure could be it two tiers at most — the tier hosting your C# code and SQL server. You need to separate concerns... Now, what is your problem?
—SA
ZurdoDev 15-Apr-15 15:59pm    
What's the question?

1 solution

you need parameter to that function

C#
public void Category_Insert(String _Category, String _Toz)
{
try
{
SqlCommand cmd = new SqlCommand("Category_Insert", SqlCon);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Category ", SqlDbType.VarChar).Value = _Category;
cmd.Parameters.Add("@Toz", SqlDbType.VarChar).Value = _Toz;
SqlCon.Open();
cmd.ExecuteNonQuery();
}


you can call it by :on button
C#
DAL.Category_Dal.Category_Insert(txtcategory.text,txttoz.text)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900