Results 1 to 10 of 10

Thread: SQL Problem

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Posts
    159

    SQL Problem

    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
    Last edited by NOTSOSURE; Mar 4th, 2004 at 05:21 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width