我有一个简单的存储过程(从 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