Click here to Skip to main content
Rate this: bad
good
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 26-Nov-12 0:49am
mona_12378
Edited 26-Nov-12 2:03am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
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.
  Permalink  
Comments
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
   
Hi,
Can you post your full code?
It will help me to understand what really are you trying to do.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try following code:-
string[] names = Receiver_Id_TextBox1.Text.Split;
int arraySize = names.Lenth;
switch(arraySize)
{
   Case 1: //assign F_name;
    Break;
   Case 2: //assign F name & Lname
    Break
   case 3: // assign all three
    Break;
}
  Permalink  
v2
Comments
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 DamithSL 445
1 Maciej Los 238
2 OriginalGriff 229
3 Zoltán Zörgő 190
4 BillWoodruff 120
0 OriginalGriff 7,969
1 DamithSL 6,139
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,309
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web01 | 2.8.141223.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