.net操作数据库

1.

自动生化曾的一些查询

可以自定义查询语句

 

2.自定义查询过程调用

USE [mydb]
GO
/****** Object:  StoredProcedure [dbo].[procLogin]    Script Date: 08/14/2017 19:18:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        <Author,,Name>
-- Create date: <Create Date,,>
-- Description:    <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[procLogin] 
    @userName varchar(50),
    @password varchar(50)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    SELECT * FROM [user] WHERE user_name = @userName AND password = @password
END

调用

SqlConneteion conn = new SqlConnection("数据库信息");
SqlCommand command = new SqlCommand("存储过程名",conn)

command.CommandType = CommandType.StoreProcedure.
command.Parameter是.Add(new SqlParameter("@userName",userName));

SqlReader dr = command.executeReader()
一行一行读 读取不到返回false

得到宿处参数值  

 

SqlParameter count = new SqlParameter("@count", 0);
count.Direction = System.Data.ParameterDirection.Output;
command.Parameters.Add(count);

 

int a= count.value();

 

posted @ 2017-08-16 15:49  jojoworld  阅读(213)  评论(0编辑  收藏  举报