Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing vb.net database application and I got 2 errors as following
I don't know why those 2 errors are occurred. Could you please help me guys?

What I have tried:

Public Class FrmRegistration
    Dim cnn As New OleDb.OleDbConnection

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        Me.txtID.Text = Nothing
        Me.txtName.Text = Nothing
        Me.txtContactNumber.Text = Nothing
        Me.txtAddress.Text = Nothing
        Me.txtEmail.Text = Nothing
        Me.btnModify.Enabled = True
        Me.btnAdd.Text = "추가"
        Me.txtID.Select()
    End Sub

    Private Sub RefreshData()
        If Not cnn.State = ConnectionState.Open Then
            'Open connection
            cnn.Open()
        End If
        Dim da As New OleDb.OleDbDataAdapter("SELECT 고객ID as [ID], " &
"성명 as [Name], 성별, 생년월일, 전화번호, 주소, email " &
" FROM People ORDER BY 고객ID", cnn)

        Dim dt As New DataTable
        'Fill data to datatable
        da.Fill(dt)
        'Offer data in a data table into datagridview
        Me.dgvData.DataSource = dt
        'Close connection
        cnn.Close()
    End Sub

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        Dim cmd As New OleDb.OleDbCommand
        If Not cnn.State = ConnectionState.Open Then
            ' Open connection if it is not yet open
            cnn.Open()
        End If
        cmd.Connection = cnn
        'check whether add new or update
        If Me.txtID.Tag & "" = "" Then
            'add new
            'add data to table
            If rbtnMale.Checked = True Then
                cmd.CommandText = "INSERT INTO People(고객ID, 성명, 성별, 생년월일, 전화번호, 주소, email)" &
            " Values(" & Me.txtID.Text & ",'" & Me.txtName.Text & "','" & Me.rbtnMale.Text & "','" & Me.DOBPicker.Value.ToShortDateString & "','" & Me.txtContactNumber.Text & "','" & Me.txtAddress.Text & "','" & Me.txtEmail.Text & "')"
                cmd.ExecuteNonQuery()
            Else
                cmd.CommandText = "INSERT INTO People(고객ID, 성명, 성별, 생년월일, 전화번호, 주소, email)" &
            " Values(" & Me.txtID.Text & ",'" & Me.txtName.Text & "','" & Me.rbtnFemale.Text & "','" & Me.DOBPicker.Value.ToShortDateString & "','" & Me.txtContactNumber.Text & "','" & Me.txtAddress.Text & "','" & Me.txtEmail.Text & "')"
                cmd.ExecuteNonQuery()
            End If
        Else
            'update data in table
            If rbtnMale.Checked = True Then
                cmd.CommandText = "UPDATE People " &
                " SET 고객ID=" & Me.txtID.Text &
                ", 성명='" & Me.txtName.Text & "'" &
                ", 성별='" & Me.rbtnMale.Text & "'" &
                ", 생년월일='" & Me.DOBPicker.Value.ToShortDateString &
                ", 전화번호='" & Me.txtContactNumber.Text & "'" &
                ", 주소='" & Me.txtAddress.Text & "'" &
                ", email ='" & Me.txtEmail.Text & "'" &
                " WHERE 고객 ID=" & Me.txtID.Tag
                cmd.ExecuteNonQuery()
            Else
                cmd.CommandText = "UPDATE People " &
         " SET 고객ID=" & Me.txtID.Text &
         ", 성명='" & Me.txtName.Text & "'" &
            ", 성별='" & Me.rbtnFemale.Text & "'" &
                ", 생년월일='" & Me.DOBPicker.Value.ToShortDateString &
                ", 전화번호='" & Me.txtContactNumber.Text & "'" &
                ", 주소='" & Me.txtAddress.Text & "'" &
                ", email ='" & Me.txtEmail.Text & "'" &
         " WHERE 고객ID=" & Me.txtID.Tag
                cmd.ExecuteNonQuery()
            End If
        End If
        'refresh data in list
        RefreshData()
        'clear form
        Me.btnClear.PerformClick()
        'close connection
        cnn.Close()
    End Sub

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub FrmRegistration_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        cnn = New OleDb.OleDbConnection
        cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.StartupPath & "\People.mdb"
        'get data into list
        Me.RefreshData()
    End Sub

    Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
        'check for the selected item in list
        If Me.dgvData.Rows.Count > 0 Then
            If Me.dgvData.SelectedRows.Count > 0 Then
                Dim intCusID As Integer = Me.dgvData.SelectedRows(0).Cells("id").Value
                'open connection
                If Not cnn.State = ConnectionState.Open Then
                    cnn.Open()
                End If
                'delete data
                Dim cmd As New OleDb.OleDbCommand
                cmd.Connection = cnn
                cmd.CommandText = "DELETE FROM People WHERE 고객ID = " & intCusID.ToString
                cmd.ExecuteNonQuery() << 1st Error occurred here
                'refresh data
                Me.RefreshData()
                'close connection
                cnn.Close()
            End If
        End If
    End Sub


    Private Sub btnModify_Click(sender As Object, e As EventArgs) Handles btnModify.Click
        If Me.dgvData.Rows.Count > 0 Then
            If Me.dgvData.SelectedRows.Count > 0 Then
                Dim intCusID As Integer = Me.dgvData.SelectedRows(0).Cells("ID").Value
                If Not cnn.State = ConnectionState.Open Then
                    cnn.Open()
                End If
                Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM People " &
" WHERE 고객ID=" & intCusID, cnn)
                Dim dt As New DataTable
                da.Fill(dt) << 2nd Error occurred here
                Me.txtID.Text = intCusID
                Me.txtName.Text = dt.Rows(0).Item("성명")
                Me.DOBPicker.Value = dt.Rows(0).Item("생년월일")
                Me.txtContactNumber.Text = dt.Rows(0).Item("전화번호")
                Me.txtAddress.Text = dt.Rows(0).Item("주소")
                Me.txtEmail.Text = dt.Rows(0).Item("email")
                'hide the id to be edited in TAG of txtstdid in case id is changed
                Me.txtID.Tag = intCusID
                'change button add to update
                Me.btnAdd.Text = "저장"
                'disable button edit
                Me.btnModify.Enabled = False
                'close connection
                cnn.Close()
            End If
        End If
    End Sub
End Class
Posted
Updated 26-Nov-16 1:27am
v3
Comments
Cristina Carrasco Angulo 1-Dec-16 13:59pm    
What are the errors?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900