X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4EA9A9DC953 for ; Mon, 19 Dec 2005 11:28:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 60686-04 for ; Mon, 19 Dec 2005 11:28:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from gk-us2.us.michelin.com (gk-us2.michelin.com [156.65.14.19]) by postgresql.org (Postfix) with ESMTP id E09F19DC810 for ; Mon, 19 Dec 2005 11:28:35 -0400 (AST) Received: from oncpfxp3-out.onc.michelin.com (unverified [10.21.4.30]) by gk-us2.us.michelin.com (Clearswift SMTPRS 5.1.7) with ESMTP id for ; Mon, 19 Dec 2005 10:28:06 -0500 Received: from ONCMH1.onc.michelin.com (ONCMH1.onc.michelin.com [156.65.124.40]) by oncpfxp3-out.onc.michelin.com (Postfix) with ESMTP id 5CC501E802 for ; Mon, 19 Dec 2005 10:28:39 -0500 (EST) Received: from oncmtap1.onc.michelin.com by oncmh1.onc.michelin.com with ESMTP for pgsql-odbc@postgresql.org; Mon, 19 Dec 2005 10:28:39 -0500 Received: from oncems01.onc.michelin.com ([156.65.125.150]) by oncmtap1.onc.michelin.com (Netscape Messaging Server 4.15) with ESMTP id IRR4BQ00.53O for ; Mon, 19 Dec 2005 10:28:38 -0500 Received: from [10.43.12.183] (unverified) by oncems01.onc.michelin.com (Content Technologies SMTPRS 4.2.5) with ESMTP id ; Mon, 19 Dec 2005 10:28:38 -0500 Message-Id: <43A6D1A3.7070705@us.michelin.com> Date: Mon, 19 Dec 2005 10:28:35 -0500 From: "Campbell, Greg" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Freeking Wu CC: pgsql-odbc@postgresql.org Subject: Re: insert and update in vb.net References: In-Reply-To: Content-Type: multipart/mixed; boundary="------------020906030304010104030005" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.614 required=5 tests=[AWL=-0.538, RCVD_IN_WHOIS_INVALID=2.151, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 1.614 X-Spam-Level: * X-Archive-Number: 200512/247 X-Sequence-Number: 6726 This is a multi-part message in MIME format. --------------020906030304010104030005 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 1. Why not use Npgsql? Are you developing one source to connect to a variety of DB backends? 2. Do you actually need commands with parameters? 3. The order of your construction seems strange. I would expect a. Create the dataset b. Update rows in the dataSET c. Use the dataAdapter w/CommandBuilder to update back to the source This way the changes to the rows, trigger the rowUpdating event when Command Builder is attached. 4. If I were not going to use the dataset,..like in your example I would use the much simpler command.ExecuteNonQuery. This would avoid transferring from server to client all the records (SELECT * FROM test) into a detatched dataset. Now if you are going to databind to a control like a grid, the issue is just the order the code units get called in. In that case you are likely to to construct and bind a dataset in a form_load() and update from the datset in a grid_afterupdate() event. Freeking Wu wrote: > 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 > --------------020906030304010104030005 Content-Type: text/x-vcard; charset=utf-8; name="greg.campbell.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="greg.campbell.vcf" begin:vcard fn:Greg Campbell n:Campbell;Greg org:Michelin North America - US5 Lexington;ENG-ASE email;internet:greg.campbell@us.michelin.com title:ASE Systems Engineer tel;work:803-951-5561/x75561 x-mozilla-html:FALSE version:2.1 end:vcard --------------020906030304010104030005--