我的vb.net代码有这个大问题。一切看起来都很好,我不知道问题出在哪里。我想提交一个记录到Access数据库,但是我每次都得到这个数据类型不匹配的错误。我的访问数据库是所有字段的文本。除了数据类型为DATE的日期以外。提交中的数据类型错误
Try
'LGCodeHygNumb()
Dim statement As String
Dim cmd As OleDbCommand
Dim connect As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Persist Security Info=false; Data Source=..\ClosedIn11.mdb")
'If connect.State = ConnectionState.Closed Then
connect.Open()
'End If
statement = "INSERT INTO EnrolleeDets (ID, Surname, FirstName, Othername, ReceiptNumber, Birthdate, Gender, MaritalStatus, HomeAddress, Mobile, Telephone, State, StateCode, Local_Govt, GroupType, GroupName, Location, ElectiveType, Provider, PassportDirectory, Original_RegDate, New_RenewalDate, ExpiryDate, Status, OverallStatus) values ('" & lblnumb.Text & "', '" & txtSurnanme.Text & "', '" & txtFirstname.Text & "', '" & txtNickname.Text & "', '" & txtReceiptNo.Text & "', '" & DatePicker1.Text & "', '" & cmbGender.Text & "', '" & cmbMaritalStatus.Text & "', '" & txtHomeAddr.Text & "', '" & txtMobile.Text & "', '" & TextBox8.Text & "', '" & cmbState.Text & "', '" & cmbStateCode.Text & "', '" & cmbLGACode.Text & "', '" & cmbGroupType.Text & "', '" & cmbGroupName.Text & "', '" & cmbLocation.Text & "', '" & cmbElectiveType.Text & "', '" & cmbProvider.Text & "', '" & txtPassportDir.Text & "','" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "', '" & txtPassportDir.Text & "')"
'MsgBox(statement)
cmd = New OleDbCommand(statement, connect)
cmd.ExecuteNonQuery()
'MsgBox(lblnumb.Text & " added under " & txtSurnanme.Text & " !", vbInformation)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
'connect.Close()
此链接会解决你目前(和将来的)问题:http://msdn.microsoft.com/en-us/ library/system.data.oledb.oledbparameter(v = vs.110).aspx –
请注意使用内联SQL进行SQL注入。 http://en.wikipedia.org/wiki/SQL_injection –
谢谢罗杰。我想我忘了补充一点,我是vb.net编程的新手。一遍又一遍仔细检查代码,我似乎没有发现任何错误的构图。除了每次我尝试提交数据库时,我总是收到数据类型不匹配。 – Joseph