Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1071521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:43:30+00:00 2026-05-16T20:43:30+00:00

In the codebehind you would add the TVP as a SqlDbType.Structured for a stored

  • 0

In the codebehind you would add the TVP as a SqlDbType.Structured for a stored procedure
But this doesn’t exist in an ASP.NET SqlDataSource control.

I have stored my Datatables in session variables (don’t worry they are small!) and I need to pass those as parameters to the SqlDataSource (which has a number of databound objects)

I pointed the Datasource to the session variable but it fails on the conversion to the table type.

EDIT:
Let’s say I take the Session variable out of the equation (because, really, it’s completely tangential)

There must be a way I can attach a DBType.Structured to a SQLDataSource.
My Listviews are appropriately databound but the store procedures to which they are attached must take TVP’s

I cannot believe that there would be no way to send a TVP paramater for a SQLDataSource?
What are my alternatives?

EDIT2:
I’ve been looking into creating a custom parameter for the SqlDataSource but it still seems to me like its “eval” method won’t be happy with the structured data type

EDIT3:
It’s beginning to appear that my only option is to do all the work in codebehind for my databound controls. I added a bounty in case anybody else has an elegant solution.

EDIT4:
Is there, perhaps, a way that I can pass the table as an object to a stored procedure, then have SQL Server convert it to the TVP?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:43:30+00:00Added an answer on May 16, 2026 at 8:43 pm

    I know you’ve edited to say session is of no importance, however I was able to get this working using a SessionParameter. I have a feeling it would also work with a ControlParameter.

    So you have a user-defined table type:

    CREATE TYPE TVPType AS TABLE(
        Col1 int,
        Col2 int)
    GO
    

    and a stored procedure that uses it:

    CREATE PROC TVPProc(@TVP AS TVPType READONLY) AS
        SELECT * FROM @TVP
    

    then a GridView bound to a SqlDataSource that selects from your sproc, passing a SessionParameter:

    <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" />
    <asp:SqlDataSource ID="SqlDataSource1" SelectCommand="TVPProc" runat="server" SelectCommandType="StoredProcedure" ConnectionString="Server=(local)\sqlexpress;Database=Graph;Integrated Security=True">
        <SelectParameters>
            <asp:SessionParameter SessionField="MyDataTable" Name="TVP" />
        </SelectParameters>
    </asp:SqlDataSource>
    

    and finally a little something to put a DataTable into the session, although you say you already have it there anyway:

    (VB)

    <script runat="server">
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim MyDataTable As New System.Data.DataTable
    
            MyDataTable.Columns.AddRange({
                New System.Data.DataColumn("Col1", GetType(integer)),
                New System.Data.DataColumn("Col2", GetType(integer))})
    
            MyDataTable.Rows.Add(22, 33)
            MyDataTable.Rows.Add(44, 55)
            MyDataTable.Rows.Add(66, 77)
    
            Session("MyDataTable") = MyDataTable
        End Sub
    </script>
    

    (C#)

    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Data.DataTable MyDataTable = new System.Data.DataTable();
            MyDataTable.Columns.AddRange(
                new System.Data.DataColumn[] {
                    new System.Data.DataColumn("Col1", typeof (int)),
                    new System.Data.DataColumn("Col2", typeof (int))});
    
            MyDataTable.Rows.Add(22, 33);
            MyDataTable.Rows.Add(44, 55);
            MyDataTable.Rows.Add(66, 77);
    
            Session["MyDataTable"] = MyDataTable;
        }
    </script>
    

    which results in a finely bound GridView:

    alt text

    and the following generated query from Profiler:

    declare @p1 dbo.TVPType
    insert into @p1 values(22,33)
    insert into @p1 values(44,55)
    insert into @p1 values(66,77)
    
    exec TVPProc @TVP=@p1
    

    This is .NET 4, MSSQL Express 2010, but should work lower as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.