如何使用vb.net将数据保存到mysql数据库

时间:2016-01-21 04:17:30

标签: mysql vb.net

hEy帮我在这段代码中发现错误:) 我是vb.net好友的新手

Try
        /*'con.Open()*/
        Query = "INSERT INTO mcs.custormer VALUES(custormer_id,first_name,last_name,nic_no,c_address1,c_address2,c_address3,c_telephoneno,membership_date,business_name,g_name,g_nicno,g_address1,g_address2,g_address3,g_telephoneNO)" & _
            "VALUES (@custormer_id,@first_name,@last_name,@nic_no,@c_address1,@c_address2,@c_address3,@c_telephoneNO,@membership_date,@business_name,@g_name,@g_nicno,@g_address1,@g_address2,@g_address3,@g_telephoneNO)"
        Using cmd = New MySqlCommand(Query, con)

            cmd.Parameters.AddWithValue("@custormer_id", Convert.ToInt32(txtcustormerid.Text))
            cmd.Parameters.AddWithValue("@first_name", Convert.ToString(txtfirstname.Text))
            cmd.Parameters.AddWithValue("@last_name", Convert.ToString(txtlastname.Text))
            cmd.Parameters.AddWithValue("@nic_no", Convert.ToString(txtnicno.Text))
            cmd.Parameters.AddWithValue("@c_address1", Convert.ToString(txtcaddress1.Text))
            cmd.Parameters.AddWithValue("@c_address2", Convert.ToString(txtcaddress2.Text))
            cmd.Parameters.AddWithValue("@c_address3", Convert.ToString(txtcaddress3.Text))
            cmd.Parameters.AddWithValue("@c_telephoneNO", Convert.ToString(txtctelephoneno.Text))
            cmd.Parameters.AddWithValue("@membership_date", Convert.ToDateTime(dtpmembrshipdate.Text))
            cmd.Parameters.AddWithValue("@business_name", Convert.ToString(txtbusinessname.Text))
            cmd.Parameters.AddWithValue("@g_name", Convert.ToString(txtgname.Text))
            cmd.Parameters.AddWithValue("@g_nicno", Convert.ToString(txtgnicno.Text))
            cmd.Parameters.AddWithValue("@g_address1", Convert.ToString(txtgaddress1.Text))
            cmd.Parameters.AddWithValue("@g_address2", Convert.ToString(txtgaddress2.Text))
            cmd.Parameters.AddWithValue("@g_address3", Convert.ToString(txtgaddress3.Text))
            cmd.Parameters.AddWithValue("@g_telephoneNO", Convert.ToString(txtgtelephoneno.Text))
            cmd.ExecuteNonQuery()
            MessageBox.Show("New Custormer Added Sucsessfully !")
            txtcustormerid.Clear()
            txtfirstname.Clear()
            txtlastname.Clear()
            txtnicno.Clear()
            txtcaddress1.Clear()
            txtcaddress2.Clear()
            txtcaddress3.Clear()
            txtctelephoneno.Clear()
            txtbusinessname.Clear()
            txtgname.Clear()
            txtgaddress1.Clear()
            txtgaddress2.Clear()
            txtgaddress3.Clear()
            txtgtelephoneno.Clear()
            txtgnicno.Clear()
        End Using
    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        'da.Dispose()
        'ds.Clear()
        ' dr.Close()
        cmd.Dispose()
        con.Close()
    End Try

单击“保存”按钮时出现此错误,

enter image description here

我尝试越来越多,但我不能前进。请帮帮我们:))

3 个答案:

答案 0 :(得分:1)

尝试

function deletePoint(deleteCircle) {
    var circleText = d3.select(deleteCircle.node()).select(function(){return this.parentNode;});
    console.log(circleText.select('text').text());   }

也请参考Mysql Insert Syntax。希望这有帮助。

答案 1 :(得分:1)

  INSERT INTO mcs.custormer
        (  /*no need to use VALUES keyword, here you are 
            specifying the column list in which data need to be  
            inserted*/ 
        custormer_id
        ,first_name
        ,last_name
        ,nic_no
        ,c_address1
        ,c_address2
        ,c_address3
        ,c_telephoneno
        ,membership_date
        ,business_name
        ,g_name
        ,g_nicno
        ,g_address1
        ,g_address2
        ,g_address3
        ,g_telephoneNO
        ) 
    VALUES ( /* use VALUES keyword, because in this clause you're  
                passing values for each columns*/
        @custormer_id
        ,@first_name
        ,@last_name
        ,@nic_no
        ,@c_address1
        ,@c_address2
        ,@c_address3
        ,@c_telephoneNO
        ,@membership_date
        ,@business_name
        ,@g_name
        ,@g_nicno
        ,@g_address1
        ,@g_address2
        ,@g_address3
        ,@g_telephoneNO
        ) 

可能的SQL插入语句

第一个表单没有指定插入数据的列名,只指定了它们的值:

INSERT INTO table_name
VALUES (value1,value2,value3,...);

第二种形式指定列名和要插入的值:

INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);

答案 2 :(得分:0)

从代码的这一部分删除“VALUES”。

INSERT INTO mcs.custormer VALUES...

正确的语法应该是:

INSERT INTO table_Name (Field1,Field2) VALUES (Value1, Value2)