0

我制作了代码vb net,可以在我的表单中显示,我使用数据集调用数据,我的编码如下

Public Function GetTableRow(ByVal strsql As String) As DataSet

        Dim conn As New SqlConnection
        Dim sDa As New SqlDataAdapter(strsql, conn)
        Dim ds As New DataSet
        Try
            sDa.Fill(ds)
        Catch ex As Exception

        End Try
        sDa.Dispose()
        Return ds
    End Function


    Private Sub CmRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmRefresh.Click

        Dim ds As New DataSet
        Dim conn = "server='server'; database='database'; user=user;password='password';"
        Dim strsql As String = "exec spSPDMonStockProductHarian '" & 230 & "'"
        ds = conn.GetTableRow(strsql)

 With Listdata
            .DataSource = ds.Tables(0)
        End With
        Koneksi.Close()
        Koneksi.Close()
    End Sub

执行此程序时出现问题,错误消息

"Public member 'Function' on type 'String' not found."

我没有得到什么问题,所以任何解决方案将不胜感激!

4

1 回答 1

0

你应该这样尝试:

    Private Sub CmRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmRefresh.Click

        Dim ds As New DataSet
        Dim conn As String = "server='server'; database='database'; user=user;password='password';"
        Dim strsql As String = "exec spSPDMonStockProductHarian '" & 230 & "'"
        ds = GetTableRow(strsql)

        If ds.Tables.Count > 0 Then
            With Listdata
                .DataSource = ds.Tables(0)
            End With
        Else
            MessageBox.Show("Dataset is empty")
        End If
        Koneksi.Close()
        Koneksi.Close()
    End Sub

我在这里所做的更改:

Dim conn As Stringds = GetTableRow(strsql)

基本上,GetTableRow是您的自定义函数,它没有在 class 中定义string

于 2013-07-12T09:27:18.697 回答