1 Replies - 2850 Views - Last Post: 18 November 2009 - 05:13 AM Rate Topic: -----

#1 Essel  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 118
  • Joined: 08-May 09

Saving checklistbox items into the database

Post icon  Posted 17 November 2009 - 02:58 PM

i am trying to add subjects and their corresponding grades to a table in you database. the table has these fields: Table1(subjCode,stdID,Grade1,Grade2,Grade3,Grade4,Grade5,Grade5,Grade6,Grade7,Grade8)

And i have a checked listbox for the subjects and another for the grades. for each subject, the re are 8 items in the chklistbox, checked. The code should insert into the database a subject and its coresponding 8 grades

but when i try to Save i gives me an exception that index out of range(index was out of the bounds of the array)
please i need help
 Dim Connect As SqlConnection
		Connect = New SqlConnection("Data Source=ESSEL-PC;Initial Catalog=Admissionprocess;Integrated Security=True")
		'Try
		Dim cmd As SqlCommand
		Dim GradeCount, i, j As Integer
		GradeCount = Me.chksubject.CheckedItems.Count
		Connect.Open()

		j = 0

		While j < GradeCount
			i = 0
			cmd = New SqlCommand("Insert Into ApplicantGrading(Subject_Code,Applicant_ID,Grade1,Grade2,Grade3,Grade4,Grade5,Grade6,Grade7,Grade8)Values('" & Me.txtsubjectcode.Text & "','" & (Me.cmbbapplicantid.SelectedItem).ToString & "','" & Me.chkgrade.CheckedItems.Item(i) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "')", Connect)
			cmd.ExecuteNonQuery()
			j += 1
			cmd.Dispose()
		End While

		'Catch ex As Exception
		'	MsgBox(ex.Message)
		'End Try
	End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Saving checklistbox items into the database

#2 theunborncoder  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 123
  • Joined: 15-October 09

Re: Saving checklistbox items into the database

Posted 18 November 2009 - 05:13 AM

hi

in single column checkedlistbox we access element as follows
CheckedListBox1.CheckedItems(0).ToString 



i am not used multiple column checkedlistbox
i think
cmd = New SqlCommand("Insert Into ApplicantGrading& #40;Subject_Code,Applicant_ID,Grade1,Grade2,Grade3,Grade4,Grade5,Grade6,Grade7,G
rade8)Values('" & Me.txtsubjectcode.Text & "','" & (Me.cmbbapplicantid.SelectedItem).ToString & "','" & Me.chkgrade.CheckedItems.Item(i) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "','" & Me.chkgrade.CheckedItems.Item(i + 1) & "')", Connect)



instead write
cmd = New SqlCommand("Insert Into ApplicantGrading& #40;Subject_Code,Applicant_ID,Grade1,Grade2,Grade3,Grade4,Grade5,Grade6,Grade7,G
rade8)Values('" & Me.txtsubjectcode.Text & "','" & (Me.cmbbapplicantid.SelectedItem).ToString & "','" & Me.chkgrade.CheckedItems.Item(i) & "','" & Me.chkgrade.CheckedItems.Item(i ) & "','" & Me.chkgrade.CheckedItems.Item(i ) & "','" & Me.chkgrade.CheckedItems.Item(i ) & "','" & Me.chkgrade.CheckedItems.Item(i ) & "','" & Me.chkgrade.CheckedItems.Item(i ) & "','" & Me.chkgrade.CheckedItems.Item(i ) & "','" & Me.chkgrade.CheckedItems.Item(i ) & "')", Connect)



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1