使用visual basic将访问数据导出为类别

时间:2014-02-15 04:09:37

标签: excel ms-access

我有这段代码:

@"SELECT * +
@"INTO [Excel 12.0 Xml;HDR=YES;DATABASE=C:\__tmp\zzzNew.xlsx].[Sheet1] " +
@"FROM SampleData";

导出时可以在哪里添加类别? WHERE Date > "& txtDate.text &

1 个答案:

答案 0 :(得分:0)

只需将WHERE子句添加到SQL语句的末尾,就像这样(在C#中,但VB.NET代码非常相似):

using (var cmd = new OleDbCommand())
{
    string txtDate_text = "2013-02-01";
    cmd.Connection = con;
    cmd.CommandText = 
            @"SELECT * " +
            @"INTO [Excel 12.0 Xml;HDR=YES;DATABASE=C:\__tmp\zzzNew.xlsx].[Sheet1] " +
            @"FROM SampleData " +
            @"WHERE [Date]=?";
    cmd.Parameters.AddWithValue("?", txtDate_text);
    cmd.ExecuteNonQuery();
}