110,566
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Windows;
using System.Data.OleDb;
namespace WpfApp9
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
String sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=D:/test.xls;" + "Extended Properties=Excel 12.0;";
//String sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=D:/test.xlsx;" + "Extended Properties=Excel 12.0;";
OleDbConnection cn = new OleDbConnection(sConnectionString);
string sqlCreate = "CREATE TABLE TestSheet ([ID] INTEGER,[Username] VarChar,[UserPwd] VarChar)";
OleDbCommand cmd = new OleDbCommand(sqlCreate, cn);
cn.Open();
cmd.ExecuteNonQuery();
cmd.CommandText = "INSERT INTO TestSheet VALUES(1,'elmer','password')";
cmd.ExecuteNonQuery();
cn.Close();
}
}
}
String strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=D:/test.xlsx;" + "Extended Properties='Excel 12.0 XML'";