我正在研究连接到SQL数据库的asp.net C#项目(MySQL 2008)。这是我的C#类:
public static DataTable GetUnitByName(string unit)
{
Database db = DatabaseFactory.CreateDatabase();
string sqlCommand = "GetUnitByName";
DbCommand dbCommandWrapper = db.GetStoredProcCommand(sqlCommand);
db.AddInParameter(dbCommandWrapper, "@Unit", DbType.String, unit);
DataSet ds = db.ExecuteDataSet(dbCommandWrapper);
DataTable dt = ds.Tables[0];
return dt;
}
以下是存储过程:
alter PROCEDURE [dbo].[GetUnitByName]
(
@Unit nvarchar
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON
DECLARE @Err int
-- Insert statements for procedure here
select * from Unit where Name=@Unit
SET @Err = @@Error
RETURN @Err
END
我打电话给这样的程序:
DataTable unit1 = Unit.GetUnitByName(per100gText [1] enter code here
); ,per10gText是一个字符串列表。
但它返回空数据表。与sql server的连接,在debuging中我看到程序无法读取参数。
任何帮助请。
答案 0 :(得分:0)
如果你想要proc返回param,你需要先将它声明为输出参数
alter PROCEDURE [dbo].[GetUnitByName]
(
@Unit nvarchar , @err int output
)
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 Unit where Name=@Unit
SET @Err = @@Error
RETURN @Err
END