为了账号安全,请及时绑定邮箱和手机立即绑定

declare table 无法得到数据

declare table 无法得到数据

天涯尽头无女友 2018-12-07 12:48:16
 不多说,直接看代码。 alter proc Proc_Product_Related( @name nvarchar(2000), @splitStr nvarchar(100) = ' ')asbegin declare @tempTable table( id int identity(1,1), ProductID int, [Name] nvarchar(255), ProductNo nvarchar(50), MemberPrice money, ThumbnailImg nvarchar(255), ProductImg nvarchar(255) ) if(@splitStr is Null) begin set @splitStr = ' '; end begin transaction insert into @tempTable select ProductID, [Name], ProductNo, MemberPrice, ThumbnailImg, ProductImg from product p, (select * from dbo.f_splitIncrease(@name, @splitStr)) f where p.name like + f.one + '%' if(@@error > 0) begin rollback transaction end select * from @tempTable if @@error > 0 rollback else commit transactionend   dbo.f_splitIncrease是我自己写的一个方法,用来分词的。我直接在Sql Server IDE中使用exec Proc_Product_Related 'the office seasons'可以得到数据集,但是我在程序中使用DataAdapter.Fill()却无法得到数据。于是我将declare table去掉,直接使用 select ProductID, [Name], ProductNo, MemberPrice, ThumbnailImg, ProductImg from product p, (select * from dbo.f_splitIncrease(@name, @splitStr)) f where p.name like + f.one + '%' 是可以得到数据的。问题就在于我加了declare table后,无法在程序端得到数据。程序端代码如下:public DataTable GetRelatedProduct(string name, string splitStr) { string strSql = "Proc_Product_Related"; DataTable dataTable = new DataTable(); OleDbParameter[] parameters ={ new OleDbParameter("@name", OleDbType.VarChar, 1000), new OleDbParameter("@splitStr", OleDbType.VarChar, 100) }; parameters[0].Value = name; if (!string.IsNullOrEmpty(splitStr)) { parameters[1].Value = splitStr; } OleDbCommand command = new OleDbCommand(); command.CommandText = strSql; command.CommandType = CommandType.StoredProcedure; command.Connection = new OleDbConnection(ConnectionString.GetConnectionString()); command.Parameters.AddRange(parameters); using (OleDbDataAdapter oledbda = new OleDbDataAdapter(command)) { oledbda.Fill(dataTable); } return dataTable; } 只是测试代码,还希望不要针对代码的优劣。
查看完整描述

2 回答

?
米脂

TA贡献1836条经验 获得超3个赞

刚才看错了回答错了,看你的存储过程和程序基本没有问题,

如果直接在Sql Server IDE中使用exec Proc_Product_Related 'the office seasons'

可以得到数据集那么程序肯定也可以,
 
应该是你程序调用出现问题了
查看完整回答
反对 回复 2019-01-21
  • 2 回答
  • 0 关注
  • 643 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信