开发者

Returning a DataTable in WCF and .NET

Thanks William, that was the ticket. Had to assign the name property on both ends [DataTable.TableName].

On a side note here: There appears to be some school of thought (no offense Marc) that the following statement is always true:

"Everything in the world can and should be made into an object."

It is, simply, not always true. There are cases where you cannot cram your 'objec开发者_运维问答t' into any cookie-cutter or class no matter how you try to customize it. For me to objectize this beast, I'd have to create roughly 4,000 objects. I don't have time to do that, and yet this project must run as a service. Frankly I think the developers at MickeySoft need to get out more into the real world, and see for themselves that although theory is great it does not represent true-life challenges. I am all for working with objects for the obvious benefits, but there is a reality that universals do not exist. In my trade, even 'most of the time' rarely happens.

Before they push out a new technology set, and cease support of an old one, they need to make sure that the new technology has the same capabilities the old one had.

For the record: The people who believe the above statement to be true are also the same people who would refuse to take the project I'm currently working on.

Just the same -- thank you both for your time, efforts and opinions!

I'm trying to create a WCF function that will return a table to my console testing app. I am a total noob. The data is 2-dimensional and looks like this:

23 Letter
42 Another Letter
43 Document
...

Here's what I'm trying to do:

<ServiceContract()> _
Public Interface ILetterWriter
    <OperationContract()> _
    Function GetLetter(ByVal LetterID As String, ByVal StateID As String, ByVal CompID As String, ByVal tblVar As DataTable) As String

    <OperationContract()> _
    Function GetLetterNames(ByVal DepartmentType As Integer) As DataTable

End Interface



    Public Function GetLetterNames(ByVal DepartmentType As Integer) As DataTable Implements ILetterWriter.GetLetterNames
        Dim SQLCon As New SqlClient.SqlConnection
        Dim SQLCmd As New SqlClient.SqlCommand

        'Connect to the database
        SQLCon.ConnectionString = "Data Source=VMSQL08-SRV1;Initial Catalog=DotNetDev;User ID=aiis_pgmr;Password=ag58102;"
        SQLCon.Open()


        'Grab the stored procedure, which returns the letter names
        SQLCmd.CommandText = "sp_GetLetters"
        SQLCmd.CommandType = CommandType.StoredProcedure
        SQLCmd.Connection = SQLCon


        'Pass the parameters
        SQLCmd.Parameters.AddWithValue("@LetterType", DepartmentType)


        'Execute the stored procedure, fill the datatable from a data adapter
        GetLetterNames = New DataTable
        GetLetterNames.Load(SQLCmd.ExecuteReader)


        'Shut it down
        SQLCmd.Dispose()
        SQLCon.Close()
        SQLCon.Dispose()
    End Function

...Of course, it won't work. I just need to get the WCF to pass a basic table to my console application. The execute SQL seems to work just fine, I just can't get the data back to my application.

Any help would be greatly appreciated.

Thanks, Jason


I agree with the other poster.

However, if you are returning a DataTable, you have to set the "Name" property of the DataTable if you want to return it from a WCF Service.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜