使用VB.net插入数据时出现问题+;MS访问(溢出)

使用VB.net插入数据时出现问题+;MS访问(溢出),vb.net,ms-access,ado.net,Vb.net,Ms Access,Ado.net,这是我为数据库课程做项目的第一个问题。我已经做了一个表单来插入员工数据 这是密码 Public Class formAddLawyer Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) FormatDateTime() End Sub Private Sub FormatDateTime() Throw New NotImplementedExceptio

这是我为数据库课程做项目的第一个问题。我已经做了一个表单来插入员工数据

这是密码

Public Class formAddLawyer
    Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs)
        FormatDateTime()
    End Sub

    Private Sub FormatDateTime()
        Throw New NotImplementedException()
    End Sub

    Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
        Me.Hide()
    End Sub

    Private Sub formAddLawyer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        myConnection = New OleDb.OleDbConnection
        Cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Mohammed\Desktop\كلية الحاسب\LawOfficeDB.accdb"
        myConnection.ConnectionString = Cs
        myConnection.Open()
    End Sub

    Private Sub btnDoAdd_Click(sender As Object, e As EventArgs) Handles btnDoAdd.Click
        mySql = "Insert into tbl_lawyer (NID, LawyerFirstName, LawyerLastName, DateOfBirth, Salary, LawyerPhone, Address) Values ("
        mySql = mySql & "" & txtLID.Text & ",'" & txtLFN.Text & "','" & txtLLN.Text & "','" & LDOB.Text & "'," & txtSalary.Text & "," & txtLPhone.Text & ",'" & txtLAddress.Text & "')"

        cmd = New OleDb.OleDbCommand
        cmd.CommandText = mySql
        cmd.Connection = myConnection
        Answer = cmd.ExecuteNonQuery()
    End Sub

    Private Sub txtLPhone_TextChanged(sender As Object, e As EventArgs) Handles txtLPhone.TextChanged

    End Sub
End Class
错误信息:

System.Data.dll中发生类型为“System.Data.OleDb.OLEDBEException”的未处理异常

附加信息:溢出


使用参数可避免sql注入和格式化问题。您没有很好地研究这个问题……并且避免了数据类型不匹配,并且通常使创建SQL查询更容易。应用于你的代码。我猜“LawyerPhone”是一个字符串,应该在“'”和“'”之间。。。但你真的应该使用参数。。。