Results 1 to 2 of 2

Thread: [2008] Value of type 'string' cannot be converted to 'System.Data.Dataset'

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2008
    Posts
    4

    [2008] Value of type 'string' cannot be converted to 'System.Data.Dataset'

    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:
    Code:
    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:
    Code:
    
    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
    Code:
    myTable = SearchWCF.DatabaseSearch(UserName, FunctionUsed)
    that is causing the error.

    Any help would be very much appreciated!


    Thanks

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Value of type 'string' cannot be converted to 'System.Data.Dataset'

    Well, the error is kind of obvious. Your DatabaseSearch function was written to return a string (event though nothing was actually returned by the function according to your code). What you need to do is rewrite the function so that it returns a dataset or datatable. Try this:
    Code:
    Public Function DatabaseSearch(ByVal UserName As String, ByVal FunctionUsed As String) As DataTable 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 dt As DataTable = New DataTable()
            da.Fill(dt)
    
            Conn.Close()
            MessageBox.Show("Connection is now closed")
    
            Return dt
    
        End Function
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width