Solved

error with substring

Posted on 2016-08-13
4
36 Views
Last Modified: 2016-08-17
hi,

I have a store procedure that returns a variable, the value is "dup", or NULL


in the asp.net page, I have an if-else

if (returnVal.ToString().Substring(0, 3) == "dup")
something
else
something

I am getting the error as seen below, am I missing something?  thanks

startIndex cannot be larger than length of string. Parameter name: startIndex

thanks
0
Comment
Question by:mcrmg
  • 2
4 Comments
 
LVL 12

Expert Comment

by:funwithdotnet
ID: 41755190
Wrap it in a  if (returnVal.ToString.length > 0) conditional.
0
 
LVL 21

Accepted Solution

by:
masterpass earned 500 total points
ID: 41755242
You could use StartWith?
Ref: https://msdn.microsoft.com/en-us/library/baketfxw(v=vs.110).aspx

The code will be something like
if (returnVal.ToString().StartsWith("dup"))
  something
else
  something

Open in new window

0
 

Author Comment

by:mcrmg
ID: 41755408
thank you very much
0
 

Author Closing Comment

by:mcrmg
ID: 41759207
thank you
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
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…

803 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