Index out of range exception in C#

Knew I should have paid attention in class

Page 1 of 1

4 Replies - 36181 Views - Last Post: 10 September 2007 - 07:49 PM Rate Topic: -----

#1 Misguided  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 02-September 07

Index out of range exception in C#

Posted 03 September 2007 - 07:52 AM

Below is my code and the information in the database is stored as type varchar. Label1 is a way of me testing to see if the right information is being passed and can be ignored at this point. If anyone can help, I would greatly appreciate it. This is the project that is due Weds.

Label1.Text=Card_Num;
			try
			{
				this.oleDbDataAdapter1.SelectCommand.Parameters[1].Value = Card_Num.ToCharArray();
			}
			catch (Exception ex)
			{
				ErrorBox.Visible=true;
				ErrorBox.Text=ex.ToString();
			}
			if(PIN.Text != bankDataset1.Cust_Pin.PINColumn.ToString())
			{
				LoginErrorMsg.Visible=true;
				PIN.Text="";
				PIN.MaxLength=4;
				Customer_Number.Text="";
			}
			else
			{
				ChooseTrans(Card_Num);
			}

			
		}



Is This A Good Question/Topic? 0
  • +

Replies To: Index out of range exception in C#

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Index out of range exception in C#

Posted 03 September 2007 - 07:57 AM

Well it seems theres an issue with the index of your Parameters for your oldb adapter. You need to post more code so I can try and help you :)
Was This Post Helpful? 0
  • +
  • -

#3 gogole  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 131
  • Joined: 17-July 07

Re: Index out of range exception in C#

Posted 06 September 2007 - 03:46 PM

i second psycocoder ,the problem must definately be with the adapters paramter index.
Was This Post Helpful? 0
  • +
  • -

#4 Misguided  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 02-September 07

Re: Index out of range exception in C#

Posted 06 September 2007 - 07:48 PM

I found out what I did wrong. I forgot to open the connection. You still have to open and close the connection even though you are using the drag and drop connection, dataadapter, and dataset. I got the project in a day late so that is not that bad, although I should have had it in Wednesday. Thanks for your help, though. It was much appreciated.
Was This Post Helpful? 0
  • +
  • -

#5 gmcarrillo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-September 07

Re: Index out of range exception in C#

Posted 10 September 2007 - 07:49 PM

The array index initalize in 0, not in 1.


View PostMisguided, on 3 Sep, 2007 - 07:52 AM, said:

Below is my code and the information in the database is stored as type varchar. Label1 is a way of me testing to see if the right information is being passed and can be ignored at this point. If anyone can help, I would greatly appreciate it. This is the project that is due Weds.

Label1.Text=Card_Num;
			try
			{
				this.oleDbDataAdapter1.SelectCommand.Parameters[1].Value = Card_Num.ToCharArray();
			}
			catch (Exception ex)
			{
				ErrorBox.Visible=true;
				ErrorBox.Text=ex.ToString();
			}
			if(PIN.Text != bankDataset1.Cust_Pin.PINColumn.ToString())
			{
				LoginErrorMsg.Visible=true;
				PIN.Text="";
				PIN.MaxLength=4;
				Customer_Number.Text="";
			}
			else
			{
				ChooseTrans(Card_Num);
			}

			
		}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1