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:
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
CodePudding user response:
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.