Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

c# No overload matches delegate 'RoutedEventHandler'

I’m trying to figure out how to fix this issue but I’m not really sure on what needs to be changed,

Here is the code:

private void UploadData_Click(object sender, RoutedEventArgs e)
        {
            string connectionstring = @"{serverconnectionstring};";
            using (SqlBulkCopy bcp = new SqlBulkCopy(connectionstring))
            {
                using (var p = new ChoCSVReader(mainFile).WithFirstLineHeader())
                {
                    bcp.DestinationTableName = "ReceiptDemo";
                    bcp.EnableStreaming = true;
                    bcp.BatchSize = 10000;
                    bcp.BulkCopyTimeout = 0;
                    bcp.NotifyAfter = 100;
                    bcp.SqlRowsCopied += delegate (object sender,SqlRowsCopiedEventArgs e)
                    {
                        Console.WriteLine(e.RowsCopied.ToString("#,##0") + " rows copied.");
                    };
                    bcp.WriteToServer(p.AsDataReader());
                }

            }
        }

The error I’m getting is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Severity    Code    Description Project File    Line    Suppression State
Error   CS0123  No overload for 'UploadData_Click' matches delegate 'RoutedEventHandler'    Rceipt  C:\Users\user\Documents\ReceiptApp\Rceipt\MainWindow.xaml   17  Active
Severity    Code    Description Project File    Line    Suppression State
Error   CS0136  A local or parameter named 'sender' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter       C:\Users\user\Documents\ReceiptApp\Rceipt\MainWindow.xaml.cs    84  

>Solution :

Let’s start with the second error: This happens because your delegate in bcp.SqlRowsCopied += delegate (object sender,SqlRowsCopiedEventArgs e) has a arguments named sender and e which are equal to an enclosing method’s arguments. Rename both arguments to something else.

The first error is probably a followup. Unless you have manually edited the method declaration, it should automatically be created when you added the event handler in the XAML editor.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading