anyone can help? i want to check whether the data has been exist or not. but its shows some error in this code.

error :No value given for one or more required parameters.

Public Sub doSave()
        Dim con As New OleDb.OleDbConnection(My.Settings.KK3DB)
        Dim cmd As New OleDb.OleDbCommand
        Dim adap As New OleDb.OleDbDataAdapter
        Dim ds As New DataSet
        Dim dr As OleDb.OleDbDataReader

        con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\backup project\KK3MailingSystem\KK3MailingSystem\KK3MailingSystem\db\KK3MailingSystem.mdb;Persist Security Info=True")
        con.Open()
        cmd.CommandText = "SELECT * FROM Staff WHERE Staff_Id =" & txtId.Text & ""
        cmd = New OleDbCommand(cmd.CommandText, con)
        dr = cmd.ExecuteReader()
        If Not dr.HasRows Then
            cmd.CommandText = " INSERT INTO Staff (Staff_Id,Staff_Name, Staff_IC,Staff_Ext,Staff_HP,Staff_Email,Staff_Position,Staff_Username) VALUES ('" + txtId.Text + "','" + txtName.Text + "','" + txtIC.Text + "','" + txtExt.Text + "','" + txtHP.Text + "','" + txtEmail.Text + "','" + cboPosition.Text + "','" + txtId.Text + "')"
            cmd = New OleDbCommand(cmd.CommandText, con)
            Dim icount As Integer = cmd.ExecuteNonQuery
            MessageBox.Show(icount)
        Else
            MsgBox(" Record exists")
        End If
    End Sub

done!

    Public Sub doSave()
        Dim con As New OleDb.OleDbConnection(My.Settings.KK3DB)
        Dim cmd As New OleDb.OleDbCommand
        Dim adap As New OleDb.OleDbDataAdapter
        Dim ds As New DataSet
        Dim dr As OleDb.OleDbDataReader

        con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\backup project\KK3MailingSystem\KK3MailingSystem\KK3MailingSystem\db\KK3MailingSystem.mdb;Persist Security Info=True")
        con.Open()
        cmd.CommandText = "SELECT * FROM Staff WHERE Staff_Id ='" & txtId.Text & "'"
        cmd = New OleDbCommand(cmd.CommandText, con)
        dr = cmd.ExecuteReader()
        If Not dr.HasRows Then
            cmd.CommandText = " INSERT INTO Staff (Staff_Id,Staff_Name, Staff_IC,Staff_Ext,Staff_HP,Staff_Email,Staff_Position,Staff_Username) VALUES ('" + txtId.Text + "','" + txtName.Text + "','" + txtIC.Text + "','" + txtExt.Text + "','" + txtHP.Text + "','" + txtEmail.Text + "','" + cboPosition.Text + "','" + txtId.Text + "')"
            cmd = New OleDbCommand(cmd.CommandText, con)
            cmd.Connection = con
            cmd.ExecuteNonQuery()
            MessageBox.Show("Data has been successfully saved.", "Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtId.Enabled = False
            txtName.Enabled = False
            txtIC.Enabled = False
            txtHP.Enabled = False
            txtExt.Enabled = False
            txtEmail.Enabled = False
            cboPosition.Enabled = False
            adap = New OleDbDataAdapter("Select * from Staff", con)
            adap.Fill(ds, "1")
            StaffDataGridView.DataSource = ds.Tables("1")
            Me.StaffDataGridView.Rows(Me.StaffDataGridView.RowCount - 2).Selected = True
            con.Close()
        Else
            MsgBox(" Staff record exist")

        End If
        end sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.