Question Value of type 'string' cannot be converted to 'System.Data.Dataset'

pagey

New member
Joined
May 12, 2008
Messages
4
Programming Experience
Beginner
Hi there,

I have a function which is accessing a database . This function is being hosted by WCF.

Once the database is accessed, I have used a select statement to retrieve some data, and this is passed to a data adapter and then a dataset.

On my client, the dataset is called, and bound to a datagrid to display the rows.

Problem is, where I'm calling the WCF function into the dataset on the client, I'm getting the error Value of type 'string' cannot be converted to 'System.Data.Dataset'. I've also tried the same thing using a datatable, but with the same error.

Here is my code in the WCF:
VB.NET:
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.ServiceModel
Imports System.Data.SqlClient
Imports System.Data


<ServiceContract()> _
Public Interface ISearchServiceContract
    <OperationContract()> _
    Function DatabaseSearch(ByVal UserName As String, ByVal FunctionUsed As String) As String
End Interface
Public Class SearchService
    Implements ISearchServiceContract

    Public Function DatabaseSearch(ByVal UserName As String, ByVal FunctionUsed As String) As String Implements ISearchServiceContract.DatabaseSearch
        Dim Conn As New SqlConnection

        Dim da As New SqlDataAdapter
        Dim query As String
        Dim myTable As New DataTable


        Conn.ConnectionString = "Data Source=BUSDEV;Initial Catalog=Northwind;User ID=vbasic;Password=vbasic"
        Conn.Open()
        MessageBox.Show("Connection is now open")

        query = "SELECT * FROM WCFTrigNP WHERE username = '" & UserName & "' AND functionused = '" & FunctionUsed & "'"
        da = New SqlDataAdapter(query, Conn)

        Dim ds As DataSet = New DataSet
        da.Fill(ds)

        Conn.Close()
        MessageBox.Show("Connection is now closed")


    End Function

    
End Class
Here is my client side code:
VB.NET:
Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
    Dim UserName As String

    Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click
        Dim SearchWCF As New SearchServiceContractClient
        Dim UserName As String
        'Dim myTable As New DataTable
        Dim myTable As New DataSet
        UserName = UserTextbox.Text
        Dim FunctionUsed As String
        FunctionUsed = ComboBox1.SelectedItem


        'myTable = SearchWCF.DatabaseSearch(UserName, FunctionUsed)

        myTable = SearchWCF.DatabaseSearch(UserName, FunctionUsed)


        DataGridView1.datasource = myTable

    End Sub

   
End Class

Its
VB.NET:
myTable = SearchWCF.DatabaseSearch(UserName, FunctionUsed)
that is causing the error.

Any help would be very much appreciated!


Thanks
 

Latest posts

Back
Top