Solved

varchar (max)

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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
Form Data Disappears Using Back Button 4 65
asp.net web application 3 58
ASP.NET Calendar Control 5 52
.NET universe documentation poster 2 22
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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

737 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