Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-15-2006, 09:21 AM   #1
Registered: May 2005
Posts: 275

Rep: Reputation: 30
Index was out of range. Must be non-negative and less than the size of the collectio

I am using a custom controls datagrid in a visual C# application. I continually got the following error when I click a button to run a query:

Index was out of range. Must be non-negative and less than the size of the collection. Her is the code that I am using to populate the datagrid:
private void DateTimePicker2_ValueChanged(object sender, System.EventArgs e)
			//Sets second date to query between
			string Selecteddate2 = DateTimePicker2.Value.Date.ToString("MM-dd-yyyy");

		public void PerformQueryIntoDataSet()
				//Declare an oracle connection
				System.Data.Odbc.OdbcConnection ODBCConnect = new System.Data.Odbc.OdbcConnection("Driver={Microsoft ODBC for Oracle};;Uid=pcc;Pwd=duferco");
				string Selecteddate = DateTimePicker1.Value.Date.ToString("MM-dd-yyyy");
				string Selecteddate2 = DateTimePicker2.Value.Date.ToString("MM-dd-yyyy");

				if (ckbx28Mill.Checked && ckbx35Mill.Checked)
					MessageBox.Show ("Please select either 28 Mill or 35 mill.");
				else if(ckbx35Mill.Checked)
				{					string Querystring = "SELECT ID FROM reported_coil_35mill@L3 where ACTUAL_DATE between TO_DATE('" + Selecteddate + ", " + cmbtime1.Text + "', 'MM-DD-YYYY, HH24:mi:SS') and TO_DATE('" + Selecteddate2 + ", " + cmbtime2.Text + "', 'MM-DD-YYYY, HH24:mi:SS')";
					System.Data.Odbc.OdbcCommand myCommand = new System.Data.Odbc.OdbcCommand(Querystring, ODBCConnect);
					DataSet1 = new DataSet("Reported Coil Data");
					Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
					//Check to see if a connection is open and if not open one
					if (ODBCConnect.State == ConnectionState.Open)
						//Close and re-open a connection
						//open connection
					//Declare and Define data adapter
					System.Data.Odbc.OdbcDataAdapter da = new System.Data.Odbc.OdbcDataAdapter(Querystring, ODBCConnect);
					System.Data.DataTable Table = new System.Data.DataTable("Level_3");

					//Fill the DataAdapter
					da.Fill(DataSet1, "Level_3");

					//Close the Connection to Oracle
					datagrid1.DataSource = DataSet1.Tables[0];
					//datagrid1.NavigateTo(0, System.Convert.ToString(- 1));
					//datagrid1.NavigateTo(0, "Level_3");
					//dataGrid.PreferredColumnWidth = 200;
					Cursor.Current = System.Windows.Forms.Cursors.Arrow;
The code is not erroring out in this sub however it errors at the end of:
static void Main()
			Application.Run(new Form1());
Does anyone know a fix or cause for this or see where the problem may be in my code?
Old 03-15-2006, 11:42 AM   #2
Registered: Jul 2004
Location: USA
Distribution: Fedora 9, LFS 6.3, Unbuntu 8.04, Slax 6.0.7
Posts: 145

Rep: Reputation: 15
Just a quick look at it, and not having all the code, I would check the DataSet1.Tables[0] call to make sure it is not returning NULL. Also you might look into pulling the Tables from the DataSet out into a DataTableCollection and then assign the tables into the datagrid from there.

Just my thoughts.
Old 03-15-2006, 11:47 AM   #3
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I know that the dataset is not null be cause when I run the query, the datagrid populates and a second or 2 later the error occurs. How do you pull the tables into a DataTableCollection like you mention?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing icon theme? i have a index.theme and index.desktop, no directions! mr_coffee Linux - Newbie 2 01-25-2006 02:45 PM
printing negative value as positive hubabuba Programming 5 05-03-2005 01:41 PM
df reporting negative disk size??? rimcrazy Linux - Hardware 2 09-07-2004 11:08 AM
/dev/hda2 negative size? yozd Linux - Hardware 4 07-24-2004 09:41 PM
Negative display for X? unholy Linux - General 0 11-15-2003 09:42 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:29 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration