Solved

error with substring

Posted on 2016-08-13
4
28 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

26 Experts available now in Live!

Get 1:1 Help Now