Solved

varchar (max)

Posted on 2016-10-13
5
45 Views
Last Modified: 2016-10-14
Hi,

One of my code is like this for one of the parameters for a stored procedure

SqlCom.Parameters.Add("@string", System.Data.SqlDbType.VarChar, 8000).Value = (strString.TrimEnd(',').TrimEnd(' '));

Is there a way to set max in asp.net?

SqlCom.Parameters.Add("@string", System.Data.SqlDbType.VarChar, max).Value = (strString.TrimEnd(',').TrimEnd(' '));
0
Comment
Question by:mcrmg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
Russ Suter earned 300 total points
ID: 41842682
Just don't include the length parameter. It is not required.
0
 
LVL 28

Assisted Solution

by:Pawan Kumar
Pawan Kumar earned 200 total points
ID: 41843405
In addition to the above comment.

SqlCom.Parameters.Add("@string", System.Data.SqlDbType.VarChar).Value = (strString.TrimEnd(',').TrimEnd(' '));

VarChar, Length - Range between 1 and 8,000 characters. In this case use same length given in the database.

Use VarChar without lenth when the database column is Varchar(max). Max can store upto 2GB in SQL Server.
0
 
LVL 20

Assisted Solution

by:Russ Suter
Russ Suter earned 300 total points
ID: 41843789
Complete side note: The Parameters.Add() function is deprecated. The preferred method now is Parameters.AddWithValue() function which doesn't even have an overload that accepts a size parameter.

https://msdn.microsoft.com/en-us/library/9dd8zze1(v=vs.110).aspx
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41843795
Ref - https://msdn.microsoft.com/en-us/library/9dd8zze1(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-3

I thinks we can provide size - 16 is what we are providing below.

Public Sub AddSqlParameter(command As SqlCommand)
  Dim param As SqlParameter = New SqlParameter( _
      "@Description", SqlDbType.NVarChar, 16)
  param.Value = "Beverages"
  command.Parameters.Add(param)
End Sub
0
 

Author Closing Comment

by:mcrmg
ID: 41843840
Thank you very much. It is good to know..thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question