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

时间:2016-04-24 19:03:42

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

我有双重和三重检查我的语法只是无法弄清楚我是否会一行一行地出错。非常适合这种支持。

1 个答案:

答案 0 :(得分:0)

使用"价值观"而不是"价值"并在值之前添加空格。