Solved

varchar (max)

Posted on 2016-10-13
5
28 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 17

Assisted Solution

by:Pawan Kumar Khowal
Pawan Kumar Khowal 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 17

Expert Comment

by:Pawan Kumar Khowal
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now