Error handling

error message

Page 1 of 1

2 Replies - 1186 Views - Last Post: 29 April 2009 - 06:34 AM Rate Topic: -----

#1 melodimoeti  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 39
  • Joined: 20-April 09

Error handling

Posted 29 April 2009 - 01:19 AM

hi there,can someone please assist.i have the code below which loads data into a combobox and on selected item it loads into a datagrid.but i get an error message saying:An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll, Additional information: Specified argument was out of the range of valid values. this is my code
   
'load datagrid for transport and travelling
		If ComboBox1.Text = ComboBox1.Items(4) Then
			cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=circuit.mdb"

			Try

				cn.Open()

			Catch ex As Exception

				MessageBox.Show(ex.Message)

			End Try

			ComboBox1.Items.Clear()

			cm.Connection = cn

			cm.CommandText = "select Number,Description from TransportTravelling"

			rd = cm.ExecuteReader()
			ComboBox1.Items.Clear()

			While (rd.Read)

				ComboBox1.Items.Contains("S13 Transport and Travelling")

			End While

			rd.Close()

			If ComboBox1.Items.Count > 4 Then

				ComboBox1.SelectedIndex = 4

			End If

			Try

				Dim adp As New Data.OleDb.OleDbDataAdapter

				Dim ds As New DataSet

				Dim dv As New DataView

				adp.SelectCommand = cm

				adp.Fill(ds, "dataset")

				dv.Table = ds.Tables(0)

				dv.Sort = "number"

				DataGrid2.DataSource = dv

				DataGrid2.Refresh()

			Catch ex As Exception
				MessageBox.Show(ex.Message)
			Finally

				cn.Close()

			End Try

		End If



Is This A Good Question/Topic? 0
  • +

Replies To: Error handling

#2 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: Error handling

Posted 29 April 2009 - 04:10 AM

This could be throwing the exception:
If ComboBox1.Text = ComboBox1.Items(4) Then

Try using:
If ComboBox1.SelectedIndex = 4 Then

Was This Post Helpful? 0
  • +
  • -

#3 melodimoeti  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 39
  • Joined: 20-April 09

Re: Error handling

Posted 29 April 2009 - 06:34 AM

View PostT3hC13h, on 29 Apr, 2009 - 12:10 PM, said:

This could be throwing the exception:
If ComboBox1.Text = ComboBox1.Items(4) Then

Try using:
If ComboBox1.SelectedIndex = 4 Then

thanks,this worked well.much appreciated
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1