Hey all
im having problems filling a ListView1 object using another form each time i click the button to fire the event nothing get's displayed in the listview1 object can any 1 help
I have one form called form2 ( and form4 (The form where the search criteria is selected using textboxes)
The database is called Pictures ad the fields are pictureID, pictureTitle, pictureDescription, pictureData
here is my code for the button on form4 to load data into the listview1 object. can any 1 help
Code:Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim frm2Search As New Form2 Dim mySqlCommand As SqlCommand mySqlCommand = New SqlCommand mySqlCommand.Connection = Me.SqlConnection1 mySqlCommand.CommandType = CommandType.Text mySqlCommand.CommandText = "SELECT pictureID, pictureTitle, pictureDescription, pictureData FROM Pictures WHERE pictureTitle LIKE @pictureTitle;" mySqlCommand.Parameters.Add(New SqlParameter("@pictureTitle", SqlDbType.Text)) mySqlCommand.Parameters("@pictureTitle").Value = "%" + Me.TextBoxTitle.Text + "%" frm2Search.ListView1.Items.Clear() Try mySqlCommand.Connection.Open() Dim myDataReader As SqlDataReader myDataReader = mySqlCommand.ExecuteReader(CommandBehavior.Default) Dim pic As picture While myDataReader.Read pic = New picture pic.pictureID = myDataReader.GetValue(0) pic.pictureTitle = myDataReader.GetValue(1) pic.pictureDescription = myDataReader.GetValue(2) pic.pictureData = New System.IO.MemoryStream(myDataReader.GetValue(3), True) Dim i As ListViewItem = New ListViewItem i.Text = pic.pictureTitle i.Tag = pic frm2Search.ListView1.Items.Add(i) End While Catch ex As Exception MessageBox.Show(ex.Message) Finally mySqlCommand.Connection.Close() End Try End Sub




Reply With Quote