---
title: "How to set TypeName in the constructor of new SqlParameter?"  
description: "How to set TypeName in the constructor of new SqlParameter?"  
author: "Anonymous User"  
published: 2014-11-20  
updated: 2014-11-21  
canonical: https://www.mindstick.com/forum/12652/how-to-set-typename-in-the-constructor-of-new-sqlparameter  
category: "mssql server"  
tags: ["c#", "asp.net", "sql server"]  
reading_time: 1 minute  

---

# How to set TypeName in the constructor of new SqlParameter?

I am using the following [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) to set up [parameters](https://www.mindstick.com/articles/87/passing-parameters-in-c-sharp) for a call to a [stored procedure](https://www.mindstick.com/articles/803/using-stored-procedure-in-asp-dot-net):

```
        List<SqlParameter>parameterList = new List<SqlParameter>();        parameterList.Add(new SqlParameter("@Title", adminTest.Title));        parameterList.Add(new SqlParameter("@Text", adminTest.Text));        var questionsList = new SqlParameter("@Questions", questions);        questionsList.TypeName = "dbo.QuestionList";        parameterList.Add(questionsList);
```

The code snippet works but what I would like to know is if [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) found a way to set the TypeName in the new [SqlParameter](https://www.mindstick.com/forum/161628/the-sqlparametercollection-only-accepts-non-null-sqlparameter-type-objects-not-sqlparameter-objects) constructor? I tried looking at the [documentation](https://answers.mindstick.com/qa/30462/what-is-documentation) but the only thing I can find is adding the typename afterwards.

## Replies

### Reply by Anonymous User

You can accomplish this with initializers. The example below specifies strongly-typed parameters and max length of variable values, which is a good practice from a SQL performance perspective.

```
    List<SqlParameter>parameterList = new List<SqlParameter>()        {            new SqlParameter("@Title",SqlDbType.VarChar) {Size = 30, Value = adminTest.Title},            new SqlParameter("@Text",SqlDbType.VarChar) {Size = 30, Value = adminTest.Text},            new SqlParameter("@Questions",SqlDbType.Structured) {TypeName = "dbo.QuestionList", Value =
questions}        };
```


---

Original Source: https://www.mindstick.com/forum/12652/how-to-set-typename-in-the-constructor-of-new-sqlparameter

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
