C# 双重查询的问题

C# 双重查询的问题,c#,ms-access,C#,Ms Access,我试图在一次点击按钮中执行2个查询。。它似乎不工作,只是自动关闭。有人能帮我或向我解释为什么我的代码不起作用吗?代码如下: test = 1; { connection.Open(); string strTemp = " [StudentNum] Text, [StudentName] Text, [Section] Text, [TimeIn] Text, [TimeOut] Text, [Status] Text"; OleDbCommand myCommand =

我试图在一次点击按钮中执行2个查询。。它似乎不工作,只是自动关闭。有人能帮我或向我解释为什么我的代码不起作用吗?代码如下:

test = 1;
{
    connection.Open();
    string strTemp = " [StudentNum] Text, [StudentName] Text, [Section] Text, [TimeIn] Text, [TimeOut] Text, [Status] Text";
    OleDbCommand myCommand = new OleDbCommand();
    myCommand.Connection = connection;
    myCommand.CommandText = "CREATE TABLE [" + date + "](" + strTemp + ")";
    myCommand.ExecuteNonQuery();
    if (test == 1)
    {
        OleDbCommand commandl = new OleDbCommand();
        commandl.Connection = connection;
        commandl.CommandText = "INSERT INTO ['" + date + "']([StudentNum],[StudentName],[Section]) select [StudentNo],[Name],[Section] from StudInfo";
        commandl.ExecuteNonQuery();
    }

删除分隔表名的撇号


commandl.CommandText=插入[+date+][StudentNum]、[StudentName]、[Section]从StudInfo中选择[StudentNo]、[Name]、[Section]

“不工作”不是一个有用的描述;您应该包括任何运行时错误,或者,希望包括捕获的异常。请参阅和。代码中没有与自动关闭相关的内容。您需要为我们提供一个表,以便了解发生了什么。我猜您的DBMS不喜欢名为2019-03-04或04/03/2019的表,或者您可能在Date中拥有的任何其他表,并且在您尚未发布的代码中,您有一个带有空代码块的捕获来处理它,但很难说。我建议你找一个好的访问教程。定义表名时不要使用撇号,只要[]。Access对使用这两种日期格式命名的表都没有问题。为什么要为特定日期创建表?@June7谢谢你的回答。。这正是我需要的