首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

实施存储过程无结果显示

2013-06-26 
执行存储过程无结果显示SQL中的代码:create assembly yhglfromM:\lll\www\procedure\yhgl\yhgl\bin\Debug

执行存储过程无结果显示
SQL中的代码:
create assembly yhgl
from'M:\lll\www\procedure\yhgl\yhgl\bin\Debug\yhgl.dll'
use DXSX
go
IF EXISTS(SELECT name FROM sysobjects WHERE name = 'yhgl_pro' AND TYPE = 'P')
DROP PROCEDURE yhgl_pro
GO
CREATE PROCEDURE yhgl_pro @username nchar(10)
AS
EXTERNAL NAME yhgl.StoredProcedures.yhgl_pro
GO
sp_configure'show advanced options',1
GO
exec sp_configure clr_enabled,1
GO
reconfigure
exec yhgl_pro 'lcf'
c#中的代码:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;


public partial class StoredProcedures
{
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void yhgl_pro( char[] username)
    {
        // 在此处放置代码
        using (SqlConnection conn = new SqlConnection("context connection = true"))
        {
            string name = "select * from [user] where username='" + username + "'";
            conn.Open();
            SqlCommand cmd = new SqlCommand(name, conn);
            SqlContext.Pipe.ExecuteAndSend(cmd);

        }
    }
};
是不是参数类型不对呢?表中有数据的。 CLR存储过程
[解决办法]
SqlContext.Pipe.ExecuteAndSend(cmd); 这里还需要带参数传递

如果你是拼接的话 就这样。

public static void yhgl_pro(string username)
      {
          // 在此处放置代码
        using (SqlConnection conn = new SqlConnection("context connection = true"))
          {
              string name = "select * from [user] where username=" + username +;
              conn.Open();
              SqlCommand cmd = new SqlCommand(name, conn);
              SqlContext.Pipe.ExecuteAndSend(cmd);

          }
      }
 

热点排行