3
我有一個簡單的存儲過程(選擇名稱,來自MyTable的ID),我想從C#(或VB.NET)調用它來填充數據集。如何運行返回數據集的存儲過程
這裏是我的代碼:
Public Class PaymentDataAccess
Public Function GetPaymentData() As DataSet
Dim cn As New SqlClient.SqlConnection
cn.ConnectionString = "Data Source=WORK-HP\BTFSERVER1;Initial Catalog=PaymentReminder;Integrated Security=True"
Dim Cmd As New SqlCommand("GetPaymentData", cn)
Cmd.CommandType = CommandType.StoredProcedure
Dim sa As New SqlDataAdapter(Cmd)
cn.Open()
Dim ds As DataSet = Nothing
Try
sa.Fill(ds)
Catch ex As Exception
Dim i As Integer = 7
End Try
Return ds
End Function
End Class
我得到一個異常的sa.Fill(ds)
{"Value cannot be null.
Parameter name: dataSet"}
System.ArgumentNullException: {"Value cannot be null.
Parameter name: dataSet"}
這裏是我的存儲過程:
USE [PaymentReminder]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetPaymentData]
AS
BEGIN
SET NOCOUNT ON;
SELECT * from Payments
END
哈哈,多麼愚蠢的錯誤! –
我不同意我的代碼,就像sa.Fill(Nothing)語句。 我仍然將一個Dataset傳遞給dataadapter,它的初始值是什麼都沒有。 –
感謝您的快速回復。 –