Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET SQL
If I give only F_Name or only F_Name & L_Name, than I get following error:
Index was outside the bounds of the array.
My code is
      string[] names = Receiver_Id_TextBox1.Text.Split;
      F_Name = names[0];
      M_Name = names[1];
      L_Name = names[2];
      cmd.CommandText = "SELECT PROFILE_ID, FIRST_NAME,MIDDLE_NAME,LAST_NAME FROM     DSProfile.HDR_PROFILE WHERE FIRST_NAME='" + F_Name + "'OR MIDDLE_NAME='" + M_Name + "' OR LAST_NAME= '" + L_Name + "' ";
      string id = Convert.ToString(cmd.ExecuteScalar());
I want to give input either F_Name, or F_Name & L_Name, or F_Name, M_Name & L_Name.
What should i do to remove exception?
Posted 25-Nov-12 23:49pm
Edited 26-Nov-12 1:03am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Have you debugged and checked what value are you getting in the names array actually?
Looking at the code it seems that names array will be having the value of Receiver_Id_TextBox1.
Debug and see whether are you getting enough values to actually initialize all of your name variables.
mona_12 at 26-Nov-12 6:06am
yes i have checked. it get proper value. but if i give only F_Name in textbox, den it give exception.
anurag3487 at 26-Nov-12 6:15am
Can you post your full code?
It will help me to understand what really are you trying to do.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Try following code:-
string[] names = Receiver_Id_TextBox1.Text.Split;
int arraySize = names.Lenth;
   Case 1: //assign F_name;
   Case 2: //assign F name & Lname
   case 3: // assign all three
mona_12 at 26-Nov-12 7:07am
Thanks... It works.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Nirav Prabtani 384
1 OriginalGriff 289
2 Sergey Alexandrovich Kryukov 225
3 _Amy 195
4 Kumarbs 144
0 OriginalGriff 7,799
1 Sergey Alexandrovich Kryukov 6,966
2 Maciej Los 3,994
3 Peter Leow 3,708
4 CHill60 2,742

Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100