[postgis-users] re: storing waypoints in Postgres

Marc Angelo computrain at paradise.net.nz
Tue Apr 4 19:37:42 PDT 2006


Managed to finally get data moving from my VB.Net into a PostGIS database last night :)

I turned to npgsql which did an excellent job (and used less code) than other types of connectors. Below is some simple code I got working to insert a waypoint into a PostGIS database


Imports System
Imports System.Data
Imports Npgsql

Private Sub Insert_Waypoints()
        Dim conn As Npgsql.NpgsqlConnection
        Dim command As Npgsql.NpgsqlCommand
        Dim SQLStr As String
        Dim rowsaffected As Int32


'these next two lines log events tha happen with npgsql - only required if things turn to custard
        NpgsqlEventLog.Level = LogLevel.Debug
        NpgsqlEventLog.LogName = "NpgsqlTests.Log"

'Connection string - just replace the details with yours
        conn = New NpgsqlConnection("SERVER=10.10.10.9;port=5432;User Id=postgres;Password=password;Database=gis2;")
        Try
            conn.Open()

'I was trying to keep it tidy so built the SQL statement bit by bit
        SQLStr = "INSERT INTO waypoints(position, annotation)"
        SQLStr = SQLStr & "VALUES("
        SQLStr = SQLStr & "GeometryFromText('POINT(172.668265 -43.538778)', 4326),"
        SQLStr = SQLStr & "'New Waypoint'"
        SQLStr = SQLStr & ")"

        command = New NpgsqlCommand(SQLStr, conn)
        rowsaffected = command.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(Prompt:=ex.ToString)
        End Try
        conn.Close()
End Sub

...npgsql actually has some great examples included in it's docs but for us VBer's we need to translate it from C#. I am unsure as to why it didn't work before.....I haven't changed the SQL statement so must of been my code.

Cheers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20060405/39a1ab45/attachment.html>


More information about the postgis-users mailing list