我有一个简单的存储过程(选择名称,来自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
答案 0 :(得分:4)
只需从
更改此行 Dim ds As DataSet = Nothing
到
Dim ds = new DataSet()
您需要将初始化的DataSet传递给SqlDataAdapter.Fill方法 实际上你的代码就像
sa.Fill(Nothing)
当然,填写代码并不理解这一点。