Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Базы";
Текущий архив: 2005.01.09;
Скачать: [xml.tar.bz2];

Вниз

DataSourse у Query   Найти похожие ветки 

 
Dmitriy O. ©   (2004-12-07 13:17) [0]

У Query есть свойство DataSourse Подскажите могу ли я как то его использовать для вставки значений от туда в другую таблицу т.е. в запросе типа Insert into table ....


 
Александр Иванов ©   (2004-12-07 13:27) [1]

А в справку слабо заглянуть?

Specifies the data source component from which to extract current field values to use with same-name parameters in the query’s SQL statement.

property DataSource: TDataSource;

Description

Set DataSource to automatically fill parameters in a query with fields values from another dataset. Parameters that have the same name as fields in the other dataset are filled with the field values. Parameters with names that are not the same as fields in the other dataset do not automatically get values, and must be programmatically set. For example, if the SQL property of the TQuery contains the SQL statement below and the dataset referenced through DataSource has a CustNo field, the value from the current record in that other dataset is used in the CustNo parameter.

SELECT *

FROM Orders O

WHERE (O.CustNo = :CustNo)

DataSource must point to a TDataSource component linked to another dataset component; it cannot point to this query’s data source component.

The dataset specified in DataSource must be created, populated, and opened before attempting to bind parameters. Parameters are bound by calling the query’s Prepare method prior to executing the query.

Tip: DataSource is especially of use when creating a master-detail relationship between tables using a linked query. It is also of use to guarantee binding for parameters that are not already set in the Params property or through a call to the ParamByName method.

If the SQL statement used by a query does not contain parameters, or all parameters are bound by the application using the Params property or the ParamByName method, DataSource need not be assigned. The example below shows setting the DataSource property of Query2 to the data source for Query1, preparing Query2, and activating Query2.

with Query2 do begin

 DataSource := DataSource1;
 Prepare;
 Open;

end;

If the SQL statement in the TQuery is a SELECT query, the query is executed using the new field values each time the record pointer in the other dataset is changed. It is not necessary to call the Open method of the TQuery each time. This makes using the DataSource property to dynamically filter a query result set useful for establishing Master-Detail relationships. Set the DataSource property in the Detail query to the TDataSource component for the Master dataset.

If the SQL statement uses other than a SELECT query (such as INSERT or UPDATE), the parameters with the same name as fields in the other dataset still get values, but the query must be explicitly executed each time the other dataset’s record pointer moves. For example, the SQL statement below uses the INSERT statement and has the parameters CustNo and CompanyName.

INSERT INTO Customer

(CustNo, Company)

VALUES (:CustNo, :CompanyName)

Another dataset, Query1 and DataSource1, has a CustNo field but no CompanyName field. If this dataset is used through the DataSource property, the CompanyName parameter must be programmatically assigned a value. Because Query1 has a CustNo field and Query1 is referenced through the DataSource property, the CustNo parameter automatically receives a value.

with Query2 do begin

 DataSource := DataSource1;
 ParamByName("CompanyName").AsString := Edit1.Text;
 Prepare;
 ExecSQL;

end;

If the SQL statement contains parameters with the same name as fields in the other dataset, do not manually set values for these parameters. Any values programmatically set, such as by using the Params property or the ParamByName method, will be overridden with automatic values. Parameters of other names must be programmatically given values. These parameters are unaffected by setting DataSource.

DataSource can be set at runtime or at design-time using the Object Inspector. At design-time, select the desired TDataSource from the drop-down list or type in the name.


 
Dmitriy O. ©   (2004-12-07 13:36) [2]

Блин с Англиски немного туговато. Как хотябы в общих чертах Это будет звучать по Русски ?


 
Dmitriy O. ©   (2004-12-07 13:36) [3]

Блин с Англиски немного туговато. Как хотябы в общих чертах Это будет звучать по Русски ?


 
Johnmen ©   (2004-12-07 13:36) [4]

Дмитрий О., может хватит ? Уже, право, не смешно...:(


 
Dmitriy O. ©   (2004-12-07 13:46) [5]


> Johnmen ©   (07.12.04 13:36) [4]

Ну не выучил я англицкий в свое время в чем щас каюсь Что сдесь смешного ?.


 
Александр Иванов ©   (2004-12-07 13:54) [6]

В Интернете есть русский хелп к Дельфи, и на крайний случай можно воспользоваться переводчиком.


 
ЮЮ ©   (2004-12-08 03:58) [7]

Можешь, если Master DataSet содержит всю необходимую информацию для параметрического запроса на вставку (Ведь InsertSQL такой же параметрический запрос, только параметры подставляютя из текущего DataSeta).

Тодько получишь неуправляемую автоматичкскую "вставлялку" + Exeption о попытке открыть запрос, не возвращающий курсор. А, это, похоже, - именно то, Вам и нравится в созданных Вами программах :)


 
Dmitriy O. ©   (2004-12-08 07:48) [8]


> ЮЮ ©   (08.12.04 03:58) [7]


> А, это, похоже, - именно то, Вам и нравится в созданных
> Вами программах

Вобщето мне это в принципе нужно для отправки данных через ADOQuery из IBdataSet в таблицу DBF. Те должна быть связка
-Набор данных сформированный с помощью select в IBDataSet из базы IB находящейся на другом компе. Мне его надо перебросить в локальную БД (или Эксель asDataBase или DBF) Поэтому я и спрашиваю могу ли я использовать IBDataSet в качестве источника данных для переброски их через Jet ядро в другие приемники данных.


 
ЮЮ ©   (2004-12-08 11:10) [9]

Если влом написать несколько строк кода (цикл по записям НД и цикл по полям НД), то есть компонент TBatchMove(.Source, Destination).

>в качестве источника данных для переброски их через Jet ядро
Jet ядро вряд ли что-то смыслит в TIBDataSet и его DataSource


 
Dmitriy O. ©   (2004-12-08 12:30) [10]


>  то есть компонент TBatchMove

Он работает через BDE. А C BDE в SQL клиент - серверном приложении не хочу связываться. Если на счет цикла то всетаки Insert into работает быстрее.


 
ЮЮ ©   (2004-12-09 06:02) [11]

>то всетаки Insert into работает быстрее

а кто спорит. Но кто-то почему-то хотел мспользовать дельфийский DataSource, который, по большому счету, не просто свести к формированию гетерогенного запроса.



Страницы: 1 вся ветка

Форум: "Базы";
Текущий архив: 2005.01.09;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.48 MB
Время: 0.04 c
3-1102584798
Malevia
2004-12-09 12:33
2005.01.09
Перемещение по датасету в DBGridEx


14-1103147175
palva
2004-12-16 00:46
2005.01.09
Ремонт видеомагнитофона или новый купить?


4-1101205001
clickmaker
2004-11-23 13:16
2005.01.09
Правка итема в листвью закрывает диалог


1-1103734070
Japp
2004-12-22 19:47
2005.01.09
Можно ли в Делфи определить номер строки PAS-файла?


1-1103812351
stelius
2004-12-23 17:32
2005.01.09
Факториал





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский