Question Bypass database row

mark103

Member
Joined
Apr 13, 2008
Messages
11
Programming Experience
3-5
Hi guys

I need your help. I am having trouble with the database row which many of my data in the database records have images and one do not have image. I did remove With Listview1 statement which it works but I need them because I have the images in the records.



Here it is the code:

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dblIP As Double
        dblIP = Dot2LongIP(TextBox1.Text)

        Dim con As New OleDb.OleDbConnection()
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source =IPCountry.mdb "
        Dim strCountry As String
        Dim olecommand As New OleDb.OleDbCommand("SELECT  country FROM ip2country  WHERE " & dblIP & " BETWEEN begin_num AND end_num ;", con)
        olecommand.Connection.Open()
        strCountry = olecommand.ExecuteScalar()
        con.Close()


        If Not strCountry Is Nothing Then
            strCountry = CountryName(strCountry)
            MessageBox.Show(strCountry)
            ListView1.Clear()
            'Connect to the database and retreive the data required from Table1 into a datatable object.
            Dim da As New System.Data.OleDb.OleDbDataAdapter( _
                    "SELECT Car, Images FROM Table1 WHERE Field1 = '" & strCountry & "' ORDER BY Car DESC", _
                    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = db1_test.mdb;Persist Security Info=False;")
            Dim dt As New DataTable
            da.Fill(dt)

            ' Place a new imagelist control onto your form designer window. The following
            ' will assign the listview to read from this control.
            ImageList1.Images.Clear()


            Dim img As Image = Nothing
            Dim imgIndex As Integer = 0
            Dim carName As String = String.Empty
            Dim listItem As ListViewItem = Nothing

            With ListView1
                .LargeImageList = ImageList1
                .SmallImageList = ImageList1
            End With

            ' Loop through each row in the database.
            For Each row As DataRow In dt.Rows
                ' First off, check we have a car name.

                If Not IsDBNull(row.Item("Car")) Then
                    carName = CStr(row.Item("Car"))
                    'We have a car, so add it to the listview
                    listItem = ListView1.Items.Add(carName)

                    'Now we check to see if we have an image for this car
                    If Not IsDBNull(row.Item("Images")) Then
                        Using ms As New IO.MemoryStream(DirectCast(row.Item("Images"), Byte()))
                            img = Image.FromStream(ms)
                            ImageList1.Images.Add("Img" & imgIndex, img)
                            listItem.ImageIndex = imgIndex
                            imgIndex += 1
                        End Using
                    End If
                End If
            Next
            Return
        End If
    End Sub



I know it would be impossible to remove the row but how about adding a new listview item without adding the database rows?? I assume that it would be possible to get pass with the following tips, for e.g.: hide the images row or end the sql connection then read the different rows table without the images row if possible to get pass??



Thanks,
Mark
 
Last edited:
Back
Top