Hi
I need help with my database. I have problem, when I input the ip address on the textbox and when I click the button, I get access to the ip country database to read the information of end num and country code to retrieve the ip as country and the program get access to my own database then they filled the wrong data that have not matched the country code or not have been separate with other data by did not ignore it. I have stored the data on the same column with other data while the country code is on the next column.
Here it is the code:
What I am trying to do: I want to read the end num and the country code columns information from the ip country database while the ip text is on the textbox and I want to find out where the ip is coming from so when I retrieve the ip as country, i want to read my own database while read the country code to find out which data I want to fills on my listview then filled the correct data that have matched the country code but ignore the other data that have not matched the country code.
How can I ignore and separate with the other data when I match the country code??
Hope you can help!
Thanks,
Mark
I need help with my database. I have problem, when I input the ip address on the textbox and when I click the button, I get access to the ip country database to read the information of end num and country code to retrieve the ip as country and the program get access to my own database then they filled the wrong data that have not matched the country code or not have been separate with other data by did not ignore it. I have stored the data on the same column with other data while the country code is on the next column.
Here it is the code:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
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()
If Not strCountry Is Nothing Then
strCountry = CountryName(strCountry)
Return
End If
Try
Catch exc As Exception
Throw exc
End Try
' 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 ORDER BY Car DESC", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\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.
With ListView1
.LargeImageList = ImageList1
.SmallImageList = ImageList1
End With
Dim img As Image
Dim intImageIndex As Integer = 0
' Loop through each row in the database.
For Each row As DataRow In dt.Rows
' First off, check we have a record value within the Car column.
If Not String.IsNullOrEmpty(row.Item("Car")) Then
' If there is an image contained within the row, retreive this into a new image object.
' Next, add this image into the imagelist control & output the car name and image to the
' listview as a newlist item. This last call references the image by index number, which
' is kept track of in the intImageIndex variable - incremented upon each loop iteration.
If Not (row.Item("Images") Is Nothing) Then
img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images"), Byte())))
ImageList1.Images.Add(row.Item("Car").ToString, img)
ListView1.Items.Add(row.Item("Car").ToString, intImageIndex)
Else
' If we arrived at this point, we have a car record entry, but no image. Therefore
' we will just output the info we do have into a new listview listitem.
ListView1.Items.Add(row.Item("Car").ToString)
End If
Else
' If we arrived here at this point in the code, then no record beneath the Car column
' exists for the row. Here we check if there's an image record and output that if
' existing in the same manner as above.
If Not (row.Item("Images") Is Nothing) Then
img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images"), Byte())))
ImageList1.Images.Add("{NULL Value}", img)
ListView1.Items.Add("{NULL Value}", intImageIndex)
End If
End If
intImageIndex += 1
Next
If ListView1.Items.Count = 2 Then
Me.ListView1.Items.Clear()
End If
End Sub
What I am trying to do: I want to read the end num and the country code columns information from the ip country database while the ip text is on the textbox and I want to find out where the ip is coming from so when I retrieve the ip as country, i want to read my own database while read the country code to find out which data I want to fills on my listview then filled the correct data that have matched the country code but ignore the other data that have not matched the country code.
How can I ignore and separate with the other data when I match the country code??
Hope you can help!
Thanks,
Mark