0
我有一個像存儲過程,從管理工作室工作正常
CREATE PROCEDURE [dbo].[ExportTestAsXML]
@TestId int
AS
BEGIN
SET NOCOUNT ON;
declare @x xml;
set @x = (
select
(select * from table1 where testid = @TestId FOR XML auto, Type, Elements),
(select * from table2 where testid = @TestId FOR XML auto, Type, Elements),
(select * from table3
where objectiveid in
(select objectiveid from objectives where testid = @TestId)
FOR XML auto, Type, Elements),
(select * from table4
where objectiveid in
(select objectiveid from objectives where testid = @TestId)
FOR XML auto, Type, Elements),
(select * from table5
where questionid in
(select questionid from questions
where objectiveid in
(select objectiveid from objectives where testid = @TestId)
)
FOR XML auto, Type, Elements)
for xml path(''), type
);
select @x as my_xml
END
一個進程。當我從SQL Server 2005 Management Studio中運行它,我得到一個表包含一個記錄組合來自select語句的XML。當我從我的Web服務代碼運行它並使用數據表可視化工具來檢查表時,它是空的。這裏是我用來執行proc的代碼
SqlParameter[] Parameters = new SqlParameter[1];
Parameters[0] = new SqlParameter();
Parameters[0].ParameterName = "@TestId";
Parameters[0].Value = TestId;
Parameters[0].SqlDbType = SqlDbType.Int;
Parameters[0].Size = 50;
DataTable data = ExecuteDataSet("ExportTestAsXML", Parameters);
private DataTable ExecuteDataSet(string storedProcName, SqlParameter[] parameters)
{
SqlCommand command = new SqlCommand();
command.CommandText = storedProcName;
command.Parameters.AddRange(parameters);
command.CommandType = CommandType.StoredProcedure;
command.Connection = (SqlConnection)dcMUPView.Connection;
command.Connection.Open();
command.Prepare();
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable ds = new DataTable();
adapter.Fill(ds);
command.Connection.Close();
return ds;
}
任何想法是怎麼回事?
@Siva可能是正確的:http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter.parametername.aspx – Yatrix
是啊,這是有道理的,但修復它後,我仍然得到相同的結果 – Josh