执行存储过程无结果显示
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);
}
}
};
是不是参数类型不对呢?表中有数据的。
------解决方案--------------------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);
}
}