'button1_click'没有重载匹配委托'system.eventhandler' [英] No overload for 'button1_click' matches delegate 'system.eventhandler'
问题描述
我试过下面的代码。
使用系统;
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Windows.Forms;
使用 System.Data.OleDb;
使用 System.Globalization;
命名空间 DEMO
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent();
}
private void brwbut_Click( object sender,EventArgs e)
{
if (openFileDialog1.ShowDialog()== DialogResult.OK )
{
textBox1.Text = openFileDialog1.FileName;
}
}
public void subbut_Click( String fileName, String tableName)
{
string connectionstring = Provider = Microsoft.ACE.OLEDB.12.0; Data Source = + fileName + ; Mode = ReadWrite;扩展属性= \Excel 8.0; HDR = NO \;
string fieldstring = (ID int, Field1 char(255),Field2 char(255));
使用(OleDbConnection conn = new OleDbConnection())
{
conn.Open();
使用(OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandText = string .Format(CultureInfo.InvariantCulture, @ CREATE TABLE [{0}] {1},tableName,fieldstring);
cmd.ExecuteNonQuery();
}
conn.Close();
}
}
public void InsertRow( String fileName, String tableName, string data)
{
string connectionString = Provider = Microsoft.ACE.OLEDB.12.0; Data Source = + fileName + ; Mode = ReadWrite;扩展属性= \Excel 8.0; HDR = YES \;
string headers = ID,Field1,字段2\" 跨度>;
使用(OleDbConnection conn = new OleDbConnection(connectionString))
{
conn.Open();
使用(OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandText = string .Format(CultureInfo.InvariantCulture, @ INSERT INTO [{0} $]({1})值({2}),tableName,headers,data);
// txtQuery.Text = cmd.CommandText;
cmd.ExecuteNonQuery( );
}
for ( int i = 0 ; i < 10 ; i ++)
{
InsertRow( C:\\ path\\\\\\ file \\Test File.xls, ListingDetails,
' + i.ToString()+ ','test +(i + 2 )。ToString()+ ','test +(i + 5 ).ToString()+ ');
}
conn.Close();
}
}
}
}
我尝试了什么:
但是我不断收到一个恼人的错误('button1_Click'没有超载匹配委托'System.EventHandler')我不知道不知道如何接近。我一直在网上搜索和解决问题一段时间,但没有找到任何答案。任何建议将不胜感激。
({1})值({2}),tableName,headers,data);
// txtQuery.Text = cmd.CommandText;
cmd.ExecuteNonQuery();
}
for ( int i = 0 ; i < 10 ; i ++)
{
InsertRow( C:\\ path\\\\\\ file \\ \\\Test File.xls, ListingDetails,
< span class =code-string> ' + i.ToString()+ 温泉n> ','test +(i + 2 )。ToString()+ ','test +(i + 5 ) .ToString()+ ');
}
conn.Close();
}
}
}
}
我尝试了什么:
但是我不断收到一个恼人的错误('button1_Click'没有超载匹配委托'System.EventHandler')我不知道不知道如何接近。我一直在网上搜索和解决问题一段时间,但没有找到任何答案。任何建议都将不胜感激。
您应该有一个名为button1_Click的方法,其签名如下所示
public void button1_Click( object sender,EventArgs e)
{
// 部分代码
}
查看文件Form1.Designer.cs
并搜索button1
并且您可能会看到错误。
您无法更改事件方法的名称或签名,而无需在引用它们的位置进行更改。
转到表格
[设计
],点击按钮( button1 ) - >右键单击 - >属性 - >点击顶部的事件标签 - >找到单击事件
并双击它。现在它将相关事件转到 Form1.cs 文件中的按钮
(或)
双击表单中的按钮[设计],它将在 Form1.cs 文件中转到它的事件
现在替换当前按钮点击事件签名
private void button1_Click()
到此
private void button1_Click( object sender,EventArgs e)
I have tried below code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Globalization;
namespace DEMO
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void brwbut_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
}
}
public void subbut_Click(String fileName, String tableName)
{
string connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Mode=ReadWrite;Extended Properties=\"Excel 8.0;HDR=NO\"";
string fieldstring = "(ID int, Field1 char(255),Field2 char(255))";
using (OleDbConnection conn = new OleDbConnection())
{
conn.Open();
using (OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandText = string.Format(CultureInfo.InvariantCulture, @"CREATE TABLE [{0}] {1}", tableName, fieldstring);
cmd.ExecuteNonQuery();
}
conn.Close();
}
}
public void InsertRow(String fileName, String tableName, string data)
{
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Mode=ReadWrite;Extended Properties=\"Excel 8.0;HDR=YES\"";
string headers = "ID,Field1,Field2";
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
conn.Open();
using (OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandText = string.Format(CultureInfo.InvariantCulture, @"INSERT INTO [{0}$] ({1}) values({2})", tableName, headers, data);
//txtQuery.Text = cmd.CommandText;
cmd.ExecuteNonQuery();
}
for (int i = 0; i < 10; i++)
{
InsertRow("C:\\path\\to\\file\\Test File.xls", "ListingDetails",
"'" + i.ToString() + "','test" + (i + 2).ToString() + "','test" + (i + 5).ToString() + "'");
}
conn.Close();
}
}
}
}
What I have tried:
But i keep getting an annoying error (No overload for 'button1_Click' matches delegate 'System.EventHandler') that I don't know how to approach. I have been searching online and trouble shooting for a while, and have not found any answers. Any suggestions would be appreciated.
({1}) values({2})", tableName, headers, data); //txtQuery.Text = cmd.CommandText; cmd.ExecuteNonQuery(); } for (int i = 0; i < 10; i++) { InsertRow("C:\\path\\to\\file\\Test File.xls", "ListingDetails", "'" + i.ToString() + "','test" + (i + 2).ToString() + "','test" + (i + 5).ToString() + "'"); } conn.Close(); } } } }
What I have tried:
But i keep getting an annoying error (No overload for 'button1_Click' matches delegate 'System.EventHandler') that I don't know how to approach. I have been searching online and trouble shooting for a while, and have not found any answers. Any suggestions would be appreciated.
You should have a method called button1_Click with the signature like below
public void button1_Click(object sender, EventArgs e) { // Some code }
Have a look inside the fileForm1.Designer.cs
and search forbutton1
and you will probably see the error.
You cannot change the names or signatures of event methods without making changes where they are referenced.
Go toForm
[Design
], Click the button(button1) -> right click -> Properties -> Click Events Tab on the top -> Find theClick Event
and Double click it. Now it will go the associated event to the button in Form1.cs File
(or)
Double Click the Button in the Form[Design], it will go to its event in Form1.cs File
now replace the current button clickevent signature
private void button1_Click()
to this
private void button1_Click(object sender, EventArgs e)
这篇关于'button1_click'没有重载匹配委托'system.eventhandler'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!