c# - MySQL synax 插入新数据时出错 c#

标签 c# mysql sql

我认为这是你需要第二双眼睛来审视的问题之一。

我尝试添加新记录,但不断收到相同的错误,即“SQL 语法错误,我正在使用 MySQL,这是表

MySQL 脚本

create table tbl_employee(
    employeeID smallint,
    employee_Fname varchar(30),
    employee_Sname varchar(30),
    employee_AddressL1 varchar(100),
    employee_AddressL2 varchar(100),
    employee_PostCode varchar(10),
    employee_tel_type enum('work', 'mobile', 'personal'),
    employee_Image varchar(250),
    employee_Job_Role     enum('admin','accounts','management','maintiantance','Sales'),     
    employee_Salary float,
    employee_imagePath varchar(250),
    employee_tel_no varchar(100),
    Primary key(employeeID)

);

这是 C# 代码

        connected = DataConnection.getConn();

        MySqlCommand cmd = new MySqlCommand("", connected); // 
        //This is my insert query in which i am taking input from the user through windows forms  
        //insert into tbl_employee value (2,'John','Rafiq','234 Zoo Rd','Alcala','2388','work' ,'admin',3500.89,'C:\blindXimages','111-111'  );
        string Query =  "Insert into tbl_employee (employeeID,employee_fname,employee_Sname,employee_AddressL1,employee_AddressL2,employee_PostCode, employee_tel_type,employee_Job_Role,employee_Salary,employee_ImagePath,employee_tel_no)" +
        "'value('" +   Convert.ToInt32(   this.txtEmployeeID.Text) + "'," + this.txtName.Text + "','" + this.txtSurname.Text + "','" + this.txtAddressL1.Text + "','" + this.txtAddressL2.Text + "','" + this.txtPostCode.Text + "','" + this.txtTelType.Text + "','" + this.txtJobRole.Text + "','" + Convert.ToDecimal( this.txtSalary.Text) + "','" + this.txtFaceName.Text + "','" + this.txtTelephoneNo.Text + "')";

        //This is command class which will handle the query and connection object.  
        MySqlCommand MyCommand2 = new MySqlCommand(Query, connected);
        MySqlDataReader MyReader2;

        MyReader2 = MyCommand2.ExecuteReader();     // Here our query will be executed and data saved into the database.  
        MessageBox.Show("Save Data");
        while (MyReader2.Read())
        {
        }
        // connected.Close();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }  

    btnAddNew.Enabled = false;
    MessageBox.Show("Data is save clearing all text boxes ");
    clearTextBox(); 
}

我对我的语法进行了双重和三次检查,只是无法弄清楚我是否逐行出错了。将非常适合这种支持。

最佳答案

使用“值”而不是“值”,并在值之前添加空格。

关于c# - MySQL synax 插入新数据时出错 c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36827609/

相关文章:

c# - 在 asp.net-mvc 中捕获每个用户的页面浏览量的最佳方法是什么

C#:管理大内存缓冲区

mysql - 按名字排序不起作用

mysql - 从两个不同的表中收集数据,Sql

c# - 在 C# 的父类上正确实现 IDisposable

c# - 展平 XML 文档

mysql - 用户 'user' @'localhost' 的访问被拒绝(使用密码 : YES) in Apache Nifi

php - 查找时间戳范围在另一个时间戳范围内的所有行

mysql - mysql中使用concat创建复合索引

mysql - 对相同结果的不同查询?