开发者

SQL Function Help

开发者 https://www.devze.com 2023-01-06 05:29 出处:网络
I am trying to archive a datagrid into a datatable so I can find 开发者_如何学Pythonit in the table by the archive date. I am using an INSERT SQL statement as follows:

I am trying to archive a datagrid into a datatable so I can find 开发者_如何学Pythonit in the table by the archive date. I am using an INSERT SQL statement as follows:

INSERT INTO [VendorArchive] ([Booth], [Deposit], [Rent], [Electric], [Security], 
[AmountPaid], [DatePaid], [PeriodPaid], [TotalDue], [Notes], [ArchiveDate], 
[BalanceDue], GETDATE());

SELECT Booth, Deposit, Rent, Electric, Security AmountPaid, DatePaid, PeriodPaid,  
TotalDue, BalanceDue, Notes
FROM Vendors

I then call the sql function in my code inside a button click event:

private void vendorArchiveToolStripButton_Click(object sender, EventArgs e)

        {

            if (MessageBox.Show("Are you sure you wish to archive?", "Perform Archive", MessageBoxButtons.YesNo) == DialogResult.Yes)

            {

                vendorArchiveTableAdapter.PerformArchive();

                MessageBox.Show("Archive has completed.");

            }



        }

When i debug and hit the archive button I get this error: "No overload for method 'PerformArchive' takes 0 arguments"

I don't understand. Am I using the wrong SQL statement? Do I need to add all the columns as argumnets in the method call?

Please help.


Your SQL query is wrong but the specific error you get has nothing to do with your SQL query.

Somewhere in your project you have a method called PerformArchive and this method takes at least one parameter. You need to provide a value for that parameter.

Assuming you are using Visual Studio, put the cursor on the method name and press F12 to go to the definition and then you can see what the parameters are.


Regarding your SQL you need something like this:

INSERT INTO [VendorArchive] (
    [Booth], [Deposit], [Rent], [Electric], [Security], [AmountPaid], [DatePaid], [PeriodPaid], [TotalDue], [BalanceDue], [Notes], [ArchiveDate]
)
SELECT
    [Booth], [Deposit], [Rent], [Electric], [Security], [AmountPaid], [DatePaid], [PeriodPaid], [TotalDue], [BalanceDue], [Notes], GETDATE()
FROM Vendors

Errors that I have fixed:

  • Removed extra semicolon.
  • Added missing comma between Security and AmountPaid.
  • Fixed the order of columns so that they match in INSERT and SELECT statements.
  • Moved GETDATE() to select list instead of insert column list.


Put your cursor on PerformArchive and press F12.

Look at the methods signature and make sure it matches where you are calling it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号