ado

How to handle ADO Query with results vs. Query with no results?

☆樱花仙子☆ 提交于 2019-12-21 05:56:34
问题 I run various SQL statements using MSSQL and ADO. The code sequence looks like this: aADOQuery.Active := False; aADOQuery.SQL.Text := ' MY SQL STATEMENT '; aADOQuery.ExecSQL; aADOQuery.Active := True; The last statement fails if the SQL return result is empty. How to check for this case to avoid run time errors? Note: The SQL statement comes from a memo where the user is typing the SQL. 回答1: If your query returns a record set ( SELECT statements) you should not use ExecSQL but simply

Connecting Excel to PostgreSQL via VBA

大憨熊 提交于 2019-12-21 04:12:15
问题 Is it possible to make query like SELECT from VBA in Excel, so I can query a PostgreSQL DB from Excel? If is possible please explain me how to connect to the database. I was looking in Google but found no results. 回答1: Create a table or view in PostgreSQL that describes the data you want. Use an ODBC or ADO connection from VBA to connect to PostgreSQL. If using ODBC you'll need to create a DSN via odbcad32.exe then use the DSN in VB, it isn't easy to just connect directly. See: Using ADO in

How Can I Sort an ADO Table on a Fieldname Containing a Space?

亡梦爱人 提交于 2019-12-20 06:36:49
问题 I am using Delphi, but this is a simple and general problem: I'm doing the following: var ArticlesTable: TADOTable; begin ArticlesTable.DisableControls; ArticlesTable.Sort := 'CITY'; ArticlesTable.First; while not ArticlesTable.Eof do begin ... ArticlesTable.Next; end; This works very well and allows me to efficiently process the records one by one with the records ordered ascending by the CITY field as they are coming in. However, now I wanted to order by the field "LAST NAME" which has an

Using ADO in VBA to connect to PostgreSQL

眉间皱痕 提交于 2019-12-20 04:56:39
问题 I am having trouble finding clear and reliable examples of connecting to a PostgreSQL database from Excel using VBA ADO. Admittedly, I am new to VBA and most examples and tutorials are very Access or MSSQL centered. (I work mostly in Ruby, Rails, Perl and PostgreSQL.) I am looking for code to connect and return a simple query (SELECT * FROM customers;) to an Excel sheet. Connection parameters (server ip, user, pass, database) are located within cells in a separate worksheet. I appreciate your

ADO Recordset Not Staying Open in VBA - “Operation is not allowed when the object is closed”

走远了吗. 提交于 2019-12-20 02:42:28
问题 I don't really understand what has happened here. I'm using Excel VBA to connect to a SQL Server Express database and return an ADO Recordset. I had it working initially, but my code was a bit messy so I created a new module and copied the code across, tidying it up as I went along. Now, when I try to run the Sub just to return a the recordcount, I get the error "The operation is not allowed when the object is closed." The code breaks on the MsgBox line. Here is the simplified code: Dim

Using a datetime parameter with ADO (ODBC) loses time part

天大地大妈咪最大 提交于 2019-12-19 19:55:29
问题 I stumbled onto this problem yesterday when I was busy writing some unit tests using SQLLite. My environment is Windows7/Delphi XE. Using TADOQuery in conjunction with a TDateTime parameter results in loss of the time part. unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ADODb, DateUtils, DB; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var

How to get the affected rows in VBA ADO Execute?

 ̄綄美尐妖づ 提交于 2019-12-19 19:13:29
问题 The following code errors on the MsgBox cn.RecordsAffected line with: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. How can I successfully get the affected number of rows? This is for an Access 2003 project. I'd prefer to keep it in 2003 format, so if there's another way to do this, that would be great. I'd like to not have to upgrade the entire project for the sake of this 1 function. Private Sub Command21_Click() On Error GoTo Err1: Dim

Requested operation requires an OLE DB Session object… - Connecting Excel to SQL server via ADO

岁酱吖の 提交于 2019-12-19 18:52:35
问题 I'm attempting to take Excel 2003 and connect it to SQL Server 2000 to run a few dynamicly generated SQL Queries which ultimately filling certain cells. I'm attempting to do this via VBA via ADO (I've tried 2.8 to 2.0) but I'm getting an error while setting the ActiveConnection variable which is inside the ADODB.Connection object. I need to resolve this pretty quick... Requested operation requires an OLE DB Session object, which is not supported by the current provider. I'm honestly not sure

Requested operation requires an OLE DB Session object… - Connecting Excel to SQL server via ADO

老子叫甜甜 提交于 2019-12-19 18:50:22
问题 I'm attempting to take Excel 2003 and connect it to SQL Server 2000 to run a few dynamicly generated SQL Queries which ultimately filling certain cells. I'm attempting to do this via VBA via ADO (I've tried 2.8 to 2.0) but I'm getting an error while setting the ActiveConnection variable which is inside the ADODB.Connection object. I need to resolve this pretty quick... Requested operation requires an OLE DB Session object, which is not supported by the current provider. I'm honestly not sure

How to add a field programatically to a TAdoTable in Delphi

左心房为你撑大大i 提交于 2019-12-19 11:28:15
问题 In my Delphi 2009 application I need to check if a field exists and if it doesn't add it during application execution. I have figured out the test for the field, but cannot get a field to add. I tried this var fld : TStringField; begin if not ADOConnection1.Connected then ADOConnection1.Open; fld := TStringField.Create(tbl); fld.FieldName := 'test'; tbl.Fields.Add(fld); end; But it doesn't work. 回答1: try this fld:= TStringField.Create(tbl); fld.FieldName := 'test'; fld.DisplayLabel := 'test';