Solved

varchar (max)

Posted on 2016-10-13
5
38 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
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 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