在3层中使用存储过程

在3层中使用存储过程

本文介绍了在3层中使用存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好......

i希望在3层中使用存储过程进行CRUD!



此程序:



 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)
结束





此数据访问层:



 使用系统; 使用 System.Data; 
使用 System.Data.SqlClient;
命名空间 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();
}
最后
{
if (SqlCon .State!= ConnectionState.Closed)
SqlCon.Close();
}
}
}
}





现在屁股......我不是知道写BLL和Button_Insert

请帮忙!

解决方案

hi guy's ...
i want use stored procedure in 3-Tier for CRUD !

this procedure :

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 :

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 !

解决方案


这篇关于在3层中使用存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 07:22