发表于:2007-08-16 16:26:00
15楼
Reading Data from an Access Table
A SELECT query can be used to read data from and Access Table or to call an Access Query. A Query is preferred over a Table if there are many more Columns in the table than are required at the time, if the data needs to be sorted or if there is a requirement to relate or join a number of Tables. The Cicode required is as follows.
Function SQLTest
INT hSQL, iResult;
hSQL = SQLConnect("DSN=ODBCTest;UID=YourUID_C;PWD=YourPWD");
IF hSQL <> -1 Then
iResult = SQLExec(hSQL, "SELECT * FROM qryRecipes WHERE Recipe Between '3000' And '6000'");
IF iResult = 0 Then
WHILE SQLNext(hSQL) = 0 DO
TraceMsg(">" + SQLGetField(hSQL, "Recipe") + "<>" +
SQLGetField(hSQL, "Flour") + "<>" +
SQLGetField(hSQL, "Water") + "<>" +
SQLGetField(hSQL, "Cocoa") + "<");
END
SQLDisconnect(hSQL);
ELSE
Message("SQL Error", SQLErrMsg, 48);
END
ELSE
Message("SQL Error", SQLErrMsg, 48);
END
END
Writing Data to an Access Table
To append data to an Access Table using ODBC, an SQL INSERT statement can be used.
Function SQLInsert
INT hSQL, iResult;
hSQL = SQLConnect("DSN=ODBCTest;UID=YourUID;PWD=YourPWD");
IF hSQL <> -1 Then
iResult = SQLExec(hSQL, "INSERT INTO tblRecipes (Recipe, Flour, Water, Cocoa) VALUES ('X1234', 2, 3, 4)" );
SQLDisconnect(hSQL);
END
END