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 8215235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:42:52+00:00 2026-06-07T11:42:52+00:00

I have a general question on whether something can be done – and whether

  • 0

I have a general question on whether something can be done – and whether it will be the most efficient way of doing it !

To summarise: can I pass an object collection as a parameter to a stored procedure?

Let’s say that I have a SQL Server table called Users [UserID, Forename, Surname]
and another table called Hobbies [HobbyID, UserID, HobbyName, HobbyTypeID]

This set up is to record multiple hobbies against a user.

In my application, I want to update the user record.

Normally – I would update the user table and then in code, loop through each hobby and update the hobbies table record by record.

If I’m updating the user forename and 2 of their hobbies, this would require 3 calls to the database.

(1 call to a stored procedure to update the forename/surname, and 2 calls to a stored procedure to update the 2 hobby records)

My question is:
Can I make just 1 call to the database by passing all the parameters to just 1 stored procedure.

eg.

intUserID = 1
strForename = "Edward"
strSurname = "ScissorHands"

dim objHobbyCollection as New List(Of Hobby)
'Assume that I have 2 hobby objects, each with their hobbyID, UserID, HobbyName & HobbyTypeID

Dim params As SqlParameter()
params = New SqlParameter() {
    New SqlParameter("@UserID", intUserID),
    New SqlParameter("@Forename", strForename),
    New SqlParameter("@Surname", strSurname),
    New SqlParameter("@Hobbies", objHobbyCollection) 
    }

Can I do this ? (and which way would be more efficient?)
What would the Stored Procedure look like ?

ALTER PROCEDURE [dbo].[User_Update]

 @UserID    INT
,@Forename      NVARCHAR(50) = NULL
,@Surname   NVARCHAR(50) = NULL
,@Hobbies   ??????????????
  • 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-06-07T11:42:54+00:00Added an answer on June 7, 2026 at 11:42 am

    Assuming SQL Server 2008+, you can do this using a table-valued parameter. First in SQL Server create a table type:

    CREATE TYPE dbo.HobbiesTVP AS TABLE
    (
      HobbyID INT PRIMARY KEY,
      HobbyName NVARCHAR(50),
      HobbyTypeID INT
    );
    

    Then your stored procedure would say:

    @Hobbies dbo.HobbiesTVP READONLY
    

    In C# (sorry I don’t know vb.net equivalent) it would be as follows (but if you just have one UserID, this doesn’t need to be part of the collection, does it?):

    // as Steve pointed out, you may need to have your hobbies in a DataTable.
    
    DataTable HobbyDataTable = new DataTable();
    HobbyDataTable.Columns.Add(new DataColumn("HobbyID"));
    HobbyDataTable.Columns.Add(new DataColumn("HobbyName"));
    HobbyDataTable.Columns.Add(new DataColumn("HobbyTypeID"));
    
    // loop through objHobbyCollection and add the values to the DataTable,
    // or just populate this DataTable in the first place
    
    using (connObject)
    {
        SqlCommand cmd = new SqlCommand("dbo.User_Update", connObject);
        cmd.CommandType = CommandType.StoredProcedure;
        // other params, e.g. @UserID
        SqlParameter tvparam = cmd.Parameters.AddWithValue("@Hobbies", HobbyDataTable);
        tvparam.SqlDbType = SqlDbType.Structured;
        // ...presumably ExecuteNonQuery()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a general question about the way that database indexing works, particularly in
I have a general question about whether people think you should use a database
I have a general question about Apache Camel. I wasn't able to find whether
I have a general question on the class definition and its use..THe below code
I have a general question about interpreters of functional languages: Are there actually any
i have a general question : i'd like to develop a facebook application using
I have a general question about the new Django 1.3 static file framework. I
I have a general question that is rather open-ended (i.e. depends on platform, application
I have a general question for the group. I am about to start a
I have a general question. I would like to have a window containing some

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.