双重查询问题

时间:2019-03-04 23:26:15

标签: c# ms-access

我试图通过单击一次按钮来执行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();
    }

1 个答案:

答案 0 :(得分:0)

删除撇号分隔表名称。

commandl.CommandText = "INSERT INTO [" + date + "]([StudentNum],[StudentName],[Section]) select [StudentNo],[Name],[Section] from StudInfo";