MATLAB DATABASE TOOLBOX RELEASE NOTES Guide de l'utilisateur Page 505

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 684
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 504
read
7-75
database with the data source named MS SQL Server Auth. MS SQL Server Auth
contains the table named productTable with 15 product records.
conn = database.ODBCConnection('MS SQL Server Auth','','');
Create a DatabaseDatastore object dbds using the database connection conn and
SQL query sqlquery. This SQL query retrieves all products from the product table
productTable ordered by product number.
sqlquery = ['select * from [toy_store].[dbo].[productTable] '...
'order by productNumber'];
dbds = datastore(conn,sqlquery);
Read the first five records in the DatabaseDatastore object dbds.
data = read(dbds,5)
data =
productNumber stockNumber supplierNumber unitCost productDescription
_____________ ___________ ______________ ________ __________________
1.00 400345.00 1001.00 14.00 'Building Blocks'
2.00 400314.00 1002.00 9.00 'Painting Set'
3.00 400999.00 1009.00 17.00 'Slinky'
4.00 400339.00 1008.00 21.00 'Space Cruiser'
5.00 400455.00 1005.00 3.00 'Tin Soldier'
data contains the query results. The row count argument 5 determines the number of
records read returns.
Close the DatabaseDatastore, cursor, and database connection.
close(dbds)
Retrieve Data and Database Information
The default output data type of any datastore is a table. Set the database preference
for the data return format 'DataReturnFormat' to table for consistency across data
types.
setdbprefs('DataReturnFormat','table')
Create a database connection conn using the native ODBC interface with Windows
Authentication. This code assumes you are connecting to a Microsoft SQL Server
Vue de la page 504
1 2 ... 500 501 502 503 504 505 506 507 508 509 510 ... 683 684

Commentaires sur ces manuels

Pas de commentaire