简体   繁体   中英

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. So I can add->query to the dataTable and select a stored procedure that then gets listed below in the table adapter section. 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.

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

Does this excerpt from MSDN help?

TableAdapters use data commands to read to and write from the database. 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. 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. When you use a TableAdapter, it effectively performs the same operations with the commands that you typically would perform. 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. 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.

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.

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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