none
Stored procedure table adapter to fill a strongly typed datatable RRS feed

  • Question

  • Environment: C#, Visual Studio 2008, SQL Server 2005 Express Edition

    This is my question:

    in my database I've got a table like this:

    ID int primary,
    NUMERICVALUE int not null,
    TEXTVALUE nchar(100) not null

    named TestTable

    then I've got a StoreProcedure named uspFilterTest which returns only some rows of TestTable, filtering them like this

    CREATE PROCEDURE [dbo].[uspFilterTest]
        @VALUE Int
    AS
    BEGIN
        SET NOCOUNT ON;
    
        SELECT *
        FROM TestTable
        WHERE TestTable.NUMERICVALUE = @VALUE
    END


    Now, if I import these database schemas in ADO.NET, I get these strongly typed items:
    a TestTableDataTable, a uspFilterTestDataTable, a TestTableTableAdapter, a uspFilterTestTableAdapter and much others that I don't care of now.

    Now I want to fill a TestTableDataTable with the values got from a uspFilterTestTableAdapter.

    Example:

    TestTableDataTable MyTable = new TestTableDataTable;
    uspFilterTestTableAdapter adapter = new uspFilterTestTableAdapter();
    adapter.Fill(MyTable, 33);

    Last row is wrong because it needs a uspFilterTestDataTable object instead of a TestTableDataTable.
    But I don't need the uspFilterTestDataTable type, I will never do it. I know that it will always be the same as a TestTableDataTable:
    SELECT *
    FROM TestTable
    same columns I mean. Hope this is clear.
    What is the smartest way to achive this goal?

    I'm a newbie in stored procedure programming, so I need help.


    ------- Life is what happens while doing other projects -------
    Wednesday, December 2, 2009 7:12 PM

Answers

  • Self solved.
    I forgot what was obvious.

    To solve my problem, I simply have to create a new item in datatable's table adapter, which takes data from an existing stored procedure instead of from sql code. Easy, clean, smart and straight. Now you can make all the logic in the database, and the app will follow.

    Thanks for reading.
    ------- Life is what happens while doing other projects -------
    • Marked as answer by Italian Cousin Wednesday, December 2, 2009 9:57 PM
    Wednesday, December 2, 2009 9:57 PM