insert and update in vb.net

From: Freeking Wu <whtech(at)gmail(dot)com>
To: pgsql-odbc(at)postgresql(dot)org
Subject: insert and update in vb.net
Date: 2005-12-19 12:45:28
Message-ID: fdf47a180512190445s1cc1744eye951164f04ee259d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-odbc

hi, I want to operate the postgres database via vb.net. I download the
postgres server 8.1 and the latest pgsql-odbc drviers. But question comes.
I can select data from db correctly . But when I insert or update the data,
no error or exception occurs. but the db takes no effect. I test the odbc
driver with access 2002 and I can update or insert data. I changed several
parameters with the connection string .But it doesn't work .How can I do?

following is my main code.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strConn As String
strConn = "DRIVER=PostgreSQL
ANSI;SERVER=localhost;PORT=5432;UID=postgres;Password=postgres;DATABASE=test;pwd=postgres;ReadOnly=0"
'strConn = "DRIVER={PostgreSQL
ANSI};UID=postgres;pwd=postgres;LowerCaseIdentifier=0;UseServerSidePrepare=0;ByteaAsLongVarBinary=0;"
_
& "Protocol=6.4;" _
& "ReadOnly=1;" _
& "SSLMODE=disable;" _
& "PORT=5432;" _
& "SERVER=localhost;" _
& "DATABASE=test;"
'strConn = "dsn=test;uid=postgres;pwd=postgres"

Dim cnDb As OdbcConnection
Dim dsDB As New DataSet
Dim adDb As OdbcDataAdapter
Dim cbDb As OdbcCommandBuilder
Dim cmd As OdbcCommand
Dim cmdIns As OdbcCommand

Try
cnDb = New OdbcConnection(strConn)
cnDb.Open()
dsDB = New DataSet
adDb = New OdbcDataAdapter
cbDb = New OdbcCommandBuilder(adDb)

' Create the SelectCommand.

cmd = New OdbcCommand("SELECT * FROM test ", cnDb) ' & _
'"WHERE id = ? ", cnDb)

'cmd.Parameters.Add("@id", OdbcType.NVarChar, "1")

adDb.SelectCommand = cmd

'adDb.UpdateCommand = New OdbcCommand(strConn, cnDb)
cmd = New OdbcCommand("UPDATE test SET name = ? " & _
"WHERE id = ?", cnDb)

cmd.Parameters.Add("@name", OdbcType.NChar, 50, "test444")
cmd.Parameters.Add("@id", OdbcType.Int, 8, 4)

adDb.UpdateCommand = cmd

cmdIns = New OdbcCommand("INSERT INTO test values(100,'100')",
cnDb)
adDb.InsertCommand = cmdIns

adDb.Fill(dsDB)
adDb.Update(dsDB)
cnDb.Close()

Finally
If Not cnDb Is Nothing Then cnDb.Dispose()
End Try
End Sub

Responses

Browse pgsql-odbc by date

  From Date Subject
Next Message Ludek Finstrle 2005-12-19 12:56:32 Re: insert and update in vb.net
Previous Message Dave Page 2005-12-19 08:48:54 Re: psqlODBC 8.01.0105 Development snapshot