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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:25:51+00:00 2026-06-19T04:25:51+00:00

The c# code below is self explanatory. I want to pass a DataTable as

  • 0

The c# code below is self explanatory. I want to pass a DataTable as a table valued parameter to a stored procedure in SQL Server 2008 through WebMatrix.Data.Database.Query but in the last line of the c# code below(i.e. appDatabase.Query) an exception is thrown

“The table type parameter ‘0’ must have a valid type name.”

public JsonResult GetUserListForRoles(int[] RoleIds)
            {
                using (Database appDatabase = Database.Open("DefaultConnection"))
                {
                    DataTable roleIdsTable = new DataTable();
                    roleIdsTable.Columns.Add("RoleId", typeof(int));

            foreach(int role in RoleIds)
            {
                roleIdsTable.Rows.Add(role);
            }


            List<UserNameIdModel> userNameIdModelList = new List<UserNameIdModel>();


 var userNameIdList = appDatabase.Query("EXEC dbo.sp_GetUserListForRoles @roleIdsList=@0", roleIdsTable);

In the Database i have created a User defined table type using this bit of TSQL

CREATE TYPE dbo.RoleIdsList AS TABLE (RoleId int)

it executed fine and shows up under Types/User-Defined Table Type in SQL Server Management Studio

This is the stored proc(Only adding the relevant portion to show that i have assigned the right type to the @roleIdsList parameter and also marked it as READONLY as is required for Table Valued parameters)

ALTER PROCEDURE [dbo].[sp_GetUserListForRoles] 
    -- Add the parameters for the stored procedure here
    @roleIdsList dbo.RoleIdsList READONLY

I have done a good deal of search but could not find the solutions that deals with WebMatrix.Data.Database… All the solutions i found involved SqlCommand and SqlParameter. I have used WebMatrix.Data.Database through out my app and need to be consistent.

PLEASE NOTE: i do not use the WebMatrix IDE. I just use this namespace in my controllers for DB interaction in my MVC4 app.

Eagerly awaiting for some guidance from someone having expertise in this. Thanks a lot in advance.

  • 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-19T04:25:53+00:00Added an answer on June 19, 2026 at 4:25 am

    According to the documentation you must specify a type name for the table-valued parameter by using the TypeName property of a SqlParameter. The WebMatrix.Data.Database helper doesn’t provide an API for specifying any aspect of a parameter except its value. It hasn’t been designed for use with stored procedures – it was initially designed for use with plain SQL only. Therefore you have no other option but to use plain ADO.NET in this instance so you can set the required properties of the SqlParameter yourself.

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

Sidebar

Related Questions

I think the question itself is pretty self-explanatory. The code is given below -
The code below is mostly self explanatory. However, I am having trouble in two
Please see the below code. I think it's pretty self explanatory. I'm running VS2010
I have the code below. I'm wondering that does the self.value and _value have
For this code example below, usually I would use [self fall]; instead of the
The comments in the code should be self explanatory. <div id=pad2></div> <input id=oscPitch type=range
I think this code and error is self-explanatory, but I don't know why? Environment:
(the example code below is self-contained and runnable, you can try it, it won't
The code below works when I want to highlight and put a check mark
I use the code below to retrieve a text data from the server in

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.