Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 插入表(列)值(电子邮件)_C#_Ms Access_Insert Into_Oledbcommand - Fatal编程技术网

C# 插入表(列)值(电子邮件)

C# 插入表(列)值(电子邮件),c#,ms-access,insert-into,oledbcommand,C#,Ms Access,Insert Into,Oledbcommand,我想在只有一列的表中插入电子邮件。我试了两条路。我第一次尝试commandText,第二次尝试Paraters。但这两种解决方案都给了我同样的错误 System.Data.OleDb.OLEDBEException:“INSERT INTO语句中出现语法错误。” 我在INSERT语句中没有看到任何错误。也许问题出在桌子上 using (OleDbCommand cmd = new OleDbCommand()) { cmd.Connection = conn; cmd.Com

我想在只有一列的表中插入电子邮件。我试了两条路。我第一次尝试commandText,第二次尝试Paraters。但这两种解决方案都给了我同样的错误

System.Data.OleDb.OLEDBEException:“INSERT INTO语句中出现语法错误。”

我在INSERT语句中没有看到任何错误。也许问题出在桌子上

 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();
}

您在(电子邮件)之后有一个“')”过多。

用户是一个关键字。您应该
插入到[USER]
中,而不是这并没有问题。我需要在表中插入用户。警觉的!这没问题,第二个字符串中没有两个),但我又犯了错误。正如这里提到的:是的,就是这样。谢谢您。
string cmdText= @"INSERT INTO User (email)) VALUES ('"+userEmail+"')";