简体   繁体   English

tableAdapter的命令和设计器中下面列出的查询之间有什么区别?

[英]What is the difference between tableAdapter's commands and queries listed below it in designer?

I have a dataset and in the designer under each dataTable there is a table adapter. 我有一个数据集,在设计器中的每个dataTable下都有一个表适配器。 So I can add->query to the dataTable and select a stored procedure that then gets listed below in the table adapter section. 因此,我可以对dataTable添加-> query并选择一个存储过程,然后在表适配器部分中列出该存储过程。 I can also select the table adapter and set it's select/insert/update/delete commands to stored procedures. 我还可以选择表适配器并将其选择/插入/更新/删除命令设置为存储过程。

My question is what is the difference and more importantly how do you know when a query or command is getting called?? 我的问题是有什么区别,更重要的是,您如何知道何时调用查询或命令? (I need to know as I can configure the parameters differently and ones aren't working right) (我需要知道,因为我可以对参数进行不同的配置,但这些参数无法正常工作)

For instance how do I know which one this is using? 例如,我怎么知道它正在使用哪一个?

    private void saveToolStripButton_Click(object sender, EventArgs e)
    {
        this.Validate();
        this.permitInfoLinksBindingSource.EndEdit();
        this.linksTableAdapter.Update(this.dataSet1);
    }

It seems that the following is properly calling the stored proc with the Environment variable... but if I try to put Environment.UserName.ToUpper() in the "Parameters Collection Editor" under SourceColumn it sends null instead. 似乎以下内容使用环境变量正确调用了存储的proc ...但是,如果我尝试将Environment.UserName.ToUpper()放在SourceColumn下的“ Parameters Collection Editor”中,则会发送null。

this.linksTableAdapter.spInsertLink(Environment.UserName.ToUpper(), fkPermitInfoID, 
fPath, ref ident);

Does this excerpt from MSDN help? MSDN的此摘录是否有帮助?

TableAdapters use data commands to read to and write from the database. TableAdapter使用数据命令来读取和写入数据库。 The TableAdapter's initial Fill (main) query is used as the basis for creating the schema of the associated data table, as well as the InsertCommand, UpdateCommand, and DeleteCommand commands associated with the TableAdapter.Update method. TableAdapter的初始Fill(主)查询用作创建关联数据表以及与TableAdapter.Update方法关联的InsertCommand,UpdateCommand和DeleteCommand命令的架构的基础。 This means that calling a TableAdapter's Update method executes the statements created when the TableAdapter was originally configured, and not one of the additional queries added with the TableAdapter Query Configuration Wizard. 这意味着调用TableAdapter的Update方法将执行最初配置TableAdapter时创建的语句,而不是使用TableAdapter查询配置向导添加的其他查询之一。 When you use a TableAdapter, it effectively performs the same operations with the commands that you typically would perform. 使用TableAdapter时,它可以有效地执行与通常执行的命令相同的操作。 For example, when you call the adapter's Fill method, the adapter executes the data command in its SelectCommand property and uses a data reader (for example, SqlDataReader) to load the result set into the data table. 例如,当您调用适配器的Fill方法时,适配器将在其SelectCommand属性中执行data命令,并使用数据读取器(例如SqlDataReader)将结果集加载到数据表中。 Similarly, when you call the adapter's Update method, it executes the appropriate command (in the UpdateCommand, InsertCommand, and DeleteCommand properties) for each changed record in the data table. 同样,当您调用适配器的Update方法时,它将为数据表中的每个更改的记录执行相应的命令(在UpdateCommand,InsertCommand和DeleteCommand属性中)。

As far as I understand, the *Command are boilerplate queries, whilst the one below the table are more specific custom stuff that you created yourself to suit your more complex needs, so if you use the commands you cannot pass more complex parameters into the query. 据我了解, *Command是样板查询,而表下方的是更具体的自定义内容,您可以根据自己的更复杂的需求创建自己的内容,因此,如果使用这些命令,则无法将更复杂的参数传递给查询。

I also surmise from this that when you call the basic actions like update etc, the default command gets executed as opposed to the a query defined afterwards. 我也由此推测,当您调用诸如update等的基本操作时,将执行默认命令,而不是随后定义的查询。

I only worked with tableadapters briefly though and my knowledge of them is quite shallow (moved over to entity framework as soon as I found out about it), so this answer night not be worth much... 虽然我只是短暂地使用了表适配器,但是我对表适配器的了解还很浅(我一经发现就移到了实体框架上),所以这个答案之夜并不值得多...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM