C# 使用c将数据插入MS Access表#

C# 使用c将数据插入MS Access表#,c#,sql,ms-access,insert,odbc,C#,Sql,Ms Access,Insert,Odbc,有人能告诉我这个密码有什么问题吗?提前谢谢 这是web应用程序插入功能的编码: 编码: string dataPath = Server.MapPath("Your DataPath"); string ConString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dataPath + ";Persist Security Info=True"; OleDbConnection C

有人能告诉我这个密码有什么问题吗?提前谢谢


这是web应用程序插入功能的编码:

编码:

    string dataPath = Server.MapPath("Your DataPath");
    string ConString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dataPath + ";Persist Security Info=True";            
    OleDbConnection Con = new OleDbConnection(ConString);
    OleDbCommand Command = Con.CreateCommand();
    Con.Open();
    Command.CommandText = "Insert into Table1(type, from, to, depart, arrival, remain) Values (@type, @from, @to, @depart, @arrival, @remain);      
    TimeSpan time = new TimeSpan(10, 7, 00);
    DateTime t = new DateTime(2016, 5, 5, 5, 4, 3);
    command.Parameters.AddWithValue("@type", "test");
    command.Parameters.AddWithValue("@from", "tet");
    command.Parameters.AddWithValue("@to", "te");
    command.Parameters.AddWithValue("@depart", t);
    command.Parameters.AddWithValue("@arrival", t);
    command.Parameters.AddWithValue("@remain", 4);
    command.ExecuteNonQuery();
    Con.Close();

这是web应用程序插入功能的编码:

编码:

    string dataPath = Server.MapPath("Your DataPath");
    string ConString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dataPath + ";Persist Security Info=True";            
    OleDbConnection Con = new OleDbConnection(ConString);
    OleDbCommand Command = Con.CreateCommand();
    Con.Open();
    Command.CommandText = "Insert into Table1(type, from, to, depart, arrival, remain) Values (@type, @from, @to, @depart, @arrival, @remain);      
    TimeSpan time = new TimeSpan(10, 7, 00);
    DateTime t = new DateTime(2016, 5, 5, 5, 4, 3);
    command.Parameters.AddWithValue("@type", "test");
    command.Parameters.AddWithValue("@from", "tet");
    command.Parameters.AddWithValue("@to", "te");
    command.Parameters.AddWithValue("@depart", t);
    command.Parameters.AddWithValue("@arrival", t);
    command.Parameters.AddWithValue("@remain", 4);
    command.ExecuteNonQuery();
    Con.Close();
您正在使用
type
from
作为表中的列名

这可能是你犯这样一个错误的原因

您可以将此类列名用方括号括起来,并将命令文本更改为:

INSERT INTO Table1([type], [from], to, depart, arrival, remain) VALUES(?, ?, ?, ?, ?, ?)
您正在使用
type
from
作为表中的列名

这可能是你犯这样一个错误的原因

您可以将此类列名用方括号括起来,并将命令文本更改为:

INSERT INTO Table1([type], [from], to, depart, arrival, remain) VALUES(?, ?, ?, ?, ?, ?)

您混合了命名参数和位置参数。仍然得到相同的错误通常您的代码看起来正常。那有什么问题吗?您是否收到异常或某些意外结果?我收到此异常:INSERT INTO语句中出现错误[42000][Microsoft][ODBC Microsoft Access Driver]语法错误。仍然收到相同的错误-这是什么错误?你不认为这可能是一条有用的信息吗?你混合了命名参数和位置参数。仍然得到相同的错误通常你的代码看起来还可以。那有什么问题吗?您是否收到异常或某些意外结果?我收到此异常:INSERT INTO语句中出现错误[42000][Microsoft][ODBC Microsoft Access Driver]语法错误。仍然收到相同的错误-这是什么错误?你不认为这是一条有用的信息吗?@Wagner'P如果答案对你有帮助,你可以将其标记为已接受。这可以为将来遇到此类问题的人提供可能的解决方案。请参阅了解详细信息。我该如何做?@Wagner'P我在之前的评论中链接的文章中描述了这一点:“要将答案标记为已接受,请单击答案旁边的复选标记,将其从灰色切换为已填写”@Wagner'P如果答案对您有帮助,您可以将其标记为已接受。这可以为将来遇到此类问题的人提供可能的解决方案。有关详细信息,请参阅。我如何做到这一点?@Wagner'P我在前面的评论中链接了一篇文章:“要将答案标记为已接受,请单击答案旁边的复选标记,将其从灰色变为已填写”