listview imagelist with sql server vb.net 2003

listview imagelist with sql server vb.net 2003

Page 1 of 1

0 Replies - 2377 Views - Last Post: 04 November 2008 - 01:29 AM Rate Topic: -----

#1 nirmala82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 12-September 08

listview imagelist with sql server vb.net 2003

Post icon  Posted 04 November 2008 - 01:29 AM

frends kindly help me,my question is suppose if the seleted ans is 3 three times the listview is getting added with images via image list,then all the added images should be stored in the place of answer1,answer2,answer3,and of the three answer one should be selected as a correct image,and all these need to be saved in database,then one more,since the list view with imagelist is have image index property is 0,if i selcted 2 from combobox,its starting from 0,1,2,but for me if it s two answer only two answers should be stored,pls let me the correction on this coding itself,experts luking for ur replies

 selanscbx = cbxNoofAns.SelectedItem
Answer1 = ""
		Answer2 = ""
		Answer3 = ""
		Anstype = ""
		Answer4 = ""
		Answer5 = ""
		Answer6 = ""
		Answer7 = ""
		Dim j As Integer
		Dim item As ListViewItem
		For j = ListView1.Items.Count - 1 To selanscbx
			Select Case j
				Case 0
					browsepic()
					ImageList1.Images.Add(System.Drawing.Image.FromFile(OpenFileDialog1.FileName))
					item = ListView1.Items.Add("Answer", j)

					MsgBox(j)
					ListView1.Items(j).ImageIndex = j
					ShowMsg("Image has successfully added to image list!", True)
				Case 1
					browsepic()
					ImageList1.Images.Add(System.Drawing.Image.FromFile(OpenFileDialog1.FileName))
					item = ListView1.Items.Add("Answer", j)
					MsgBox(j)
					ListView1.Items(j).ImageIndex = j
				Case 2
					browsepic()
					ImageList1.Images.Add(System.Drawing.Image.FromFile(OpenFileDialog1.FileName))
					item = ListView1.Items.Add("Answer", j)
					MsgBox(j)
					ListView1.Items(j).ImageIndex = j
				Case 3
					browsepic()
					ImageList1.Images.Add(System.Drawing.Image.FromFile(OpenFileDialog1.FileName))
					item = ListView1.Items.Add("Answer", j)
					MsgBox(j)
					ListView1.Items(j).ImageIndex = j
				Case 4
					browsepic()
					ImageList1.Images.Add(System.Drawing.Image.FromFile(OpenFileDialog1.FileName))
					item = ListView1.Items.Add("Answer", j)
					MsgBox(j)
					Answer5 = ListView1.Items(j).ImageIndex = j
				Case 5
					browsepic()
					ImageList1.Images.Add(System.Drawing.Image.FromFile(OpenFileDialog1.FileName))
					item = ListView1.Items.Add("Answer", j)
					MsgBox(j)
					Answer6 = ListView1.Items(j).ImageIndex = j
				Case 6
					browsepic()
					ImageList1.Images.Add(System.Drawing.Image.FromFile(OpenFileDialog1.FileName))
					item = ListView1.Items.Add("Answer", j)
					MsgBox(j)
					Answer7 = ListView1.Items(j).ImageIndex = j
			End Select
		Next
		Dim ms As New IO.MemoryStream
'Here picturebox is used instead i need to have listview.selected image should be stored as correctans and the images in listview are added as answer1,answer2,answer3 in database in image format
		PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)

		Dim arrImage() As Byte = ms.GetBuffer

		ms.Close()
		CorrectAns = listview1.SelectedItems
		Anstype = cbxQtype.SelectedItem
		NumberofAns = cbxNoofAns.SelectedItem
		QuestionName = txtQuestion.Text
		Qid = Val(txtQid.Text)
		sSql = "insert into Question(Qid,QuestionName,NumberOFAns,Anstype,Answer1,Answer2,Answer3,Answer4,Answer5,Answer6,Answer7,CorrectAns) values('" & Qid.ToString & "','" & QuestionName.ToString & "','" & NumberofAns.ToString & "','" & Anstype.ToString & "','" & Answer1& "','" & Answer2 & "','" & Answer3 & "','" & Answer4 & "','" & Answer5 & "','" & Answer6 & "','" & Answer7 & "','" & CorrectAns & "')"
		sqlcommand.Connection = Sqlcon
		sqlcommand.CommandText = sSql
		sqlcommand.CommandType = CommandType.Text
		Try
			sqlcommand.ExecuteNonQuery()
			ShowMsg("Question_Answer(s) added !", True)
			ClearAllFields()
		Catch ex As Exception
			ShowMsg("Please Click AddQuestion button to Proceed", False)
		End Try
		txtQuestion.Focus()



** Edit ** :code:

Is This A Good Question/Topic? 0
  • +

Page 1 of 1