pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Campbell, Greg <greg.campbell@us.michelin.com>
To: dodol garut <jangkaru80@yahoo.com>
To: pgsql-odbc@postgresql.org
Subject: Re: Need help postgre with visual basic
Date: Wed, 08 Mar 2006 15:19:33 -0500
Message-ID: <440F3C55.8090400@us.michelin.com> (raw)
In-Reply-To: <20060308153229.15246.qmail@web37601.mail.mud.yahoo.com>
References: <20060308153229.15246.qmail@web37601.mail.mud.yahoo.com>

Hi dodol garut.
Your applicaton looks nearly workable.

Recommendations:
1. Use care when sending code that contains a connection string with password.
2. Use pgAdmin to build your database creation scripts.
3. Use VB help, particulary MSDN to nail down syntax of ADO commands.
4. Name your global supermarkt ADO Connection object something like gcnnSupermarket intead of 
dbSupermarket. Almost all connection objects are named "cnn"-something or "conn"-something. The "g" is 
just an indication or a variable that is global to your applicaiton.
5. Test your connection string in isolation, to see if that works.
6. Rather than applying adUseClient to the connection object apply it to each recordset
(e.g. rs.CursorLocation = adUseClient)
7. Do NOT use adDynamic for a cursor type parameter, (unless you REALLY REALLY mean to).
8. Eliminate statements that do nothing (e.g. ExecuteSQL = AffectedRecords).
ExecuteSQL was supposed to be an function, but that function is not in your code, and it would be on the 
other side of the equals sign.
9. Once you get the select and insert to work, explore PostgreSQL functions. They act like stored 
procedures. Syntax is like "SELECT insert_produk(kodeproduk,namaproduk,hargasatuan)". See PostgreSQL docs 
on how to build functions (return type void). pgAdmin again makes this pretty easy. pgAdmin is your friend.

expected code:
Sub cmdSave()

      on error goto err_sub

     'change to a single-ton select to guarantee the return on only one record, as long as the table exists
     StrSQL1 = "select count(*) as kode_count from produk where kodeproduk='" & Text1.Text & "'"

     Set rsValid = New ADODB.Recordset
     rsCursorLocation = adUseClient 'put the client cursor location here, just to be sure

     'for a read only 1 record query use adForwardOnly and adLockReadOnly
     rsValid.Open StrSQL1, utama.gcnnSupermarket, adOpenForwardOnly, adlockReadOnly, adCmdText

     If (rsValid("kode_count") = 0) Then
         StrSql2 = "insert into produk(kodeproduk,namaproduk,hargasatuan) values('" & _
                    Text1.Text & "','" & _Text2.Text & "'," & Text3.Text & ")"

	'better yet use a Stored Procedure for faster execution and to  move db syntax/logic to database
         'StrSql2 = "SELECT insert_produk('" & Text1.Text & "','" & _Text2.Text & "'," & Text3.Text & ")"

         utama.gnnSupermarket.Execute StrSql2 [, AffectedCount, adCmdText] 'don't really need stuff in 
brackets
	.
	.
	.

     Else
        ...
     End If

     set rsValid = Nothing
     exit Sub

err_sub:
     'err handling, msg boxes, etc.

End sub



dodol garut wrote:
> I try to build a simple  visual basic project with PostgreSQL. Here i attach that project.
>   That project still have problem and i need someone please to solve that problem.
>   For query is in supermarket.sql
>   Thanx before
>    
>   best regards,
>   ERIS RISO
>   Indonesia
> 
> Send instant messages to your online friends http://uk.messenger.yahoo.com 
> 
> 
> ------------------------------------------------------------------------
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>        choose an index scan if your joining column's datatypes do not
>        match

Attachments:

greg.campbell.vcf (text/x-vcard, 239B) download 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

view thread (2+ messages)

Message-ID: <440F3C55.8090400@us.michelin.com>
Permalink:  ../440F3C55.8090400@us.michelin.com/
Also on:    postgresql.org/message-id/440F3C55.8090400@us.michelin.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: greg.campbell@us.michelin.com, jangkaru80@yahoo.com
  Subject: Re: Need help postgre with visual basic
  In-Reply-To: <440F3C55.8090400@us.michelin.com>
  References: <20060308153229.15246.qmail@web37601.mail.mud.yahoo.com> <440F3C55.8090400@us.michelin.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox