资 源 简 介
C#添加删除修改数据并生成Excel工作表格,private void Button4_Click(object sender, EventArgs e)
{//新建工作表(在Excel文件型数据源中不支持删除操作)
var MyConnectString =@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=运货商.xlsx;Extended Properties=""Excel 12.0;HDR=YES"";";
var MyConnection=new OleDbConnection(MyConnectString);
if(MyConnection.State == ConnectionState.Closed)
MyConnection.Open();
var MySQL = "CREATE TABLE 新运货商(公司名称 char(50), 电话 char(20));";
var MyCommand=new OleDbCommand(MySQL, MyConnection);
MyCommand.ExecuteNonQuery();
MySQL = "INSERT INTO [新运货商$](公司名称,电话)VALUES ( +this.TextBox1.Text+,+this.TextBox2.Text+)";
MyCommand = new OleDbCommand(MySQL, MyConnection);
MyCommand.ExecuteNonQuery();
MySQL = "SELECT * FROM [新运货商$]";
var MyAdapter=new OleDbDataAdapter(MySQL, MyConnectString);
var MyTable=new DataTable();
MyAdapter.Fill(MyTable);
this.DataGridView1.DataSource = MyTable;
}