hi,
i need to execute a query for each button in VB. example to insert,delete etc....
please suggest quick reply

Dani AI

Generated

— pragmatic pattern: keep the UI handlers tiny and factor all database work into one shared module that the button Click events call. is right that each button runs its own code, but duplicating connection/execute logic in every Click makes maintenance harder. asked how the query is called; the exact implementation depends on the database (Access, SQL Server, etc.), so the shared module should expose simple helpers such as ExecSQL(sql As String) As Long for non-query commands and a GetRecordset(...)/parameterized routine for selects.

Practical, up-to-date pointers (VB6 + ADO):

  • Add a reference to "Microsoft ActiveX Data Objects x.x Library" (ADO 2.x/2.8 is commonly used with VB6).
  • Keep one place for connection open/close and for executing commands; this centralizes error handling and logging.
  • Never build SQL by concatenating untrusted input — use ADO Command objects with Parameters or stored procedures to avoid injection.
  • Match the OLE DB provider/ODBC driver to the database and to VB6's 32-bit runtime (driver architecture must match). Modern Microsoft OLE DB drivers supersede older providers.
  • For responsiveness and reliability: open per-call for short utilities, or open once for form lifetime but handle reconnects and network errors; use transactions with BeginTrans/CommitTrans/RollbackTrans when multiple statements must succeed together.

These points implement the quick, safe pattern suggested earlier while addressing driver and security considerations that matter today.

Recommended Answers

All 2 Replies

just insert your codes on button each event..
actually, post your code first.. so we can help you.

Lets see your query and how you call the same from VB.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.