日期:2014-05-18 浏览次数:20476 次
data.Open(); sql = "select * from a"; SqlCommand comm = new SqlCommand(sql, data.con); SqlDataReader dr = data.Re_dr(comm); while (dr.Read()) { str = dr["text"] ; }
create proc SelectFromA as begin select * from a end
------解决方案--------------------
首先在sqlserver中创建存储过程
ex:
create proc selectAllFromMBC as select PC_Model_ID,BR.PC_Brand_Name,PC_Model_Name,PC_Color_Name from PC_Model as PC inner join PC_Brand as BR on PC.PC_Brand_ID=BR.PC_Brand_ID inner join PC_color as CO on PC.PC_Color_ID=CO.PC_Color_ID go
------解决方案--------------------
if exists (select * from dbo.sysobjects where id= object_id(N'[dbo].select') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
drop procedure [dbo].[select]
go
CREATE PROCEDURE select
(
@id varchar(10)
//这里写参数
)
AS
select * from a
GO
拿到数据库上执行一下就行了。在数据库的可编程性-》存储过程中可以查看到。
------解决方案--------------------
CREATE PROCEDURE MyProc AS Delete From db Where a='1' Delete From db1 Where b='2' ---这就是一个存储过程
------解决方案--------------------
打开企业管理器->找到Northwind数据库->选中存储过程项->右键菜单->新建存储过程.
到这一步会弹出一个让你写存储过程的界面.在里面输入如下代码:
CREATE proc proc_Test ( @Total int ) as begin if(@Total >0) begin select * from Employees end else begin select top 4 * from Employees end end GO
------解决方案--------------------