INSERT INTO Table(列)VALUE(电子邮件)
INSERT INTO Table (Column) VALUE (email)
我想在 Table 中插入只有一栏的电子邮件。我尝试了两种方式。我第一次尝试使用 commandText,第二次尝试使用护栏。但是这两种解决方案都给我同样的错误。
System.Data.OleDb.OleDbException: 'Syntax error in INSERT INTO statement.'
我在 INSERT STATEMENT 中没有看到任何错误。也许问题出在 TABLE?
using (OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandText = "SELECT COUNT (email) FROM [User] WHERE [email] LIKE '" + userEmail + "';";
conn.Open();
int count = Convert.ToInt32(cmd.ExecuteScalar()); // This passed
if (count == 0)
{
string query = @"INSERT INTO User (email) VALUES (@email)";
string cmdText= @"INSERT INTO User (email) VALUES ('"+userEmail+"')";
OleDbCommand command = new OleDbCommand(cmdText, conn);
// command.Parameters.AddWithValue("@email", "userEmail");
// command.CommandText = query;
command.ExecuteNonQuery(); // I GOT ERROR HERE
}
conn.Close();
}
string cmdText= @"INSERT INTO User (email)) VALUES ('"+userEmail+"')";
您在 (email) 后的 ')' 太多了
User
是关键字。你应该 INSERT INTO [USER]
而不是
我想在 Table 中插入只有一栏的电子邮件。我尝试了两种方式。我第一次尝试使用 commandText,第二次尝试使用护栏。但是这两种解决方案都给我同样的错误。
System.Data.OleDb.OleDbException: 'Syntax error in INSERT INTO statement.'
我在 INSERT STATEMENT 中没有看到任何错误。也许问题出在 TABLE?
using (OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandText = "SELECT COUNT (email) FROM [User] WHERE [email] LIKE '" + userEmail + "';";
conn.Open();
int count = Convert.ToInt32(cmd.ExecuteScalar()); // This passed
if (count == 0)
{
string query = @"INSERT INTO User (email) VALUES (@email)";
string cmdText= @"INSERT INTO User (email) VALUES ('"+userEmail+"')";
OleDbCommand command = new OleDbCommand(cmdText, conn);
// command.Parameters.AddWithValue("@email", "userEmail");
// command.CommandText = query;
command.ExecuteNonQuery(); // I GOT ERROR HERE
}
conn.Close();
}
string cmdText= @"INSERT INTO User (email)) VALUES ('"+userEmail+"')";
您在 (email) 后的 ')' 太多了
User
是关键字。你应该 INSERT INTO [USER]
而不是