假设我的存储过程是:
IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'sp_QB_descriptionwise_select')
BEGIN
DROP Procedure sp_QB_descriptionwise_select
END
GO
CREATE Procedure sp_QB_descriptionwise_select
(
@description nvarchar(max)
)
AS
declare @type int
SELECT Question.questionid, Question.question, Question.answer, Question.typeOfQuestion, QuestionBank.description
FROM QuestionBank INNER JOIN
Question ON QuestionBank.questionid = Question.questionid
WHERE (QuestionBank.description = @description)
SELECT @type = Question.typeOfQuestion
FROM QuestionBank INNER JOIN
Question ON QuestionBank.questionid = Question.questionid
WHERE (QuestionBank.description = @description)
if @type=1
begin
SELECT OptionQuestion.option1, OptionQuestion.option2, OptionQuestion.option3, OptionQuestion.option4
FROM OptionQuestion INNER JOIN
Question ON OptionQuestion.questionid = Question.questionid
end
GO
如何以何种方式存储记录?
答案 0 :(得分:3)
使用IDataReader
/ ExecuteReader
,您应该可以使用:
using (IDataReader reader = cmd.ExecuteReader())
{
do
{
while (reader.Read())
{
/* row */
}
} while (reader.NextResult()); /* grid */
}
答案 1 :(得分:0)
使用DataSetAdapter.Fill()方法调用存储过程。它将使用所有结果表填充数据集。如果使用类型化数据集,请确保设置表映射(填充DataSetAdapter.TableMappings集合)。详细信息可在MSDN上找到
答案 2 :(得分:0)
DataSetCommand.selectCommand接受参数为sqlcommand.commandText,sqlConnction如何在这种情况下传递参数???