Solved

error with substring

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

732 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