在3层中使用存储过程? [英] use stored procedure in 3 Tier ?
本文介绍了在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
请帮忙!
解决方案
你需要参数到那个功能
public void Category_Insert(字符串 _Category,字符串 _Toz)
{
尝试
{
SqlCommand cmd = new SqlCommand( Category_Insert,SqlCon);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add( @ Category,SqlDbType.VarChar).Value = _类别;
cmd.Parameters.Add( @ Toz,SqlDbType.VarChar).Value = _Toz;
SqlCon.Open();
cmd.ExecuteNonQuery();
}
您可以通过以下方式拨打电话:按钮
DAL.Category_Dal.Category_Insert(txtcategory.text,txttoz.text)
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 !
解决方案
you need parameter to that function
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
DAL.Category_Dal.Category_Insert(txtcategory.text,txttoz.text)
这篇关于在3层中使用存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文