Solved

varchar (max)

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

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 29

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

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 …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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