If String.IsNullOrWhiteSpace(txtadmin.Text) Or String.IsNullOrWhiteSpace(txtname.Text) Or String.IsNullOrWhiteSpace(txtcourse.Text) Or String.IsNullOrWhiteSpace(txtic.Text) Or String.IsNullOrWhiteSpace(txtgender.Text) Or String.IsNullOrWhiteSpace(txtaddress.Text) Or String.IsNullOrWhiteSpace(txtbirth.Text) Or String.IsNullOrWhiteSpace(txttel.Text) Or String.IsNullOrWhiteSpace(txtemail.Text) Or String.IsNullOrWhiteSpace(txttpye.Text) Then
MessageBox.Show("Please complete the on the box.", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim Conn As System.Data.OleDb.OleDbConnection
Dim ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\temp\Database1.accdb"
Conn = New System.Data.OleDb.OleDbConnection(ConnectionString)
Try
If Conn.State = ConnectionState.Open Then Conn.Close()
Conn.Open()
Dim sql As String = "INSERT INTO tbl_info ([AdminNo],UserName, [Course Title], ICNo, Gender, Address, [Data of Birth], TelNo, Email, Type) values ('" & txtname.Text & "', '" & txtadmin.Text & "', '" & txtcourse.Text & "', '" & txtic.Text & "', '" & txtgender.Text & "', '" & txtaddress.Text & "','" & txtbirth.Text & "', '" & txttel.Text & "', '" & txtemail.Text & "', '" & txttpye.Text & "')"
Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql)
sqlCom.Connection = Conn
Dim result As Integer = sqlCom.ExecuteNonQuery
sqlCom.Dispose()
Conn.Close()
이 라인에서 "구문 오류가 쿼리 식 (누락 오류)"233 sangkeng 번째 # 6-12 (s'451233 ') ""오류가 :구문 오류 (누락 오류가)
Dim result As Integer = sqlCom.ExecuteNonQuery
하지만 주소에 난 어쨌든 ggghh처럼 그것이
If result > 0 Then
MessageBox.Show("Successfully created.")
Else
MessageBox.Show("Failure to create.")
End If
txtname.Text = ""
txtadmin.Text = ""
txtcourse.Text = ""
txtic.Text = ""
txtgender.Text = ""
txtaddress.Text = ""
txtbirth.Text = ""
txttel.Text = ""
txtemail.Text = ""
txttpye.Text = ""
txtadmin.Focus()
'Catch ex As Exception
'MessageBox.Show("Failed to connect to Database..", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
'End Try
질문을 올바르게 형식화하십시오. –
문자열 연결을 사용하여 SQL 코드에 값을 삽입하지 마십시오. 항상 매개 변수를 사용하십시오. 그렇게하면 문제가 해결됩니다. http://jmcilhinney.blogspot.com.au/2009/08/using-parameters-in-adonet.html – jmcilhinney