【发布时间】:2016-11-01 12:05:08
【问题描述】:
谁能告诉我这段代码有什么问题?提前致谢。
myConnection.ConnectionString = myConnectionString;
myConnection.Open();
OdbcCommand command = myConnection.CreateCommand();
command.CommandText =
"INSERT INTO Table1(type, from, to, depart, arrival, remain) VALUES(?, ?, ?, ?, ?, ?)";
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();
【问题讨论】:
-
您正在混合命名参数和位置参数。
-
仍然出现同样的错误
-
一般来说你的代码看起来没问题。那么它有什么问题呢?您是否遇到异常或某些意外结果?
-
我收到此异常:错误 [42000] [Microsoft][ODBC Microsoft Access Driver] INSERT INTO 语句中的语法错误。
-
仍然出现同样的错误 - 那是什么错误?您不认为这可能是一条有用的信息吗?
标签: c# sql ms-access insert odbc