none
visual studio 2010 code to prevent duplicate entry or avoiding the same value in textbox RRS feed

  • Question

  • Please help me to write a code for my window form to avoid user to enter the existing value or text in excel column.

    The following code is the present I have in my visual studio 2010 editor.

            

    Private Sub BtnSave_Click(sender As System.Object, e As System.EventArgs) Handles BtnSave.Click

            TxtDate.Text = DateTimePicker1.Value.ToShortDateString
            cn.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=C:\Users\myComputer\Desktop\VB 2010 to Excel\MasterLog.xls;extended properties=excel 8.0;"
            cn.Open()
            dt.Clear()
            With cm
                .Connection = cn
                .CommandText = "Insert into [DataMasterLog$]values('" & TxtInvoice.Text & "','" & TxtDate.Text & "','" & TxtSupplier.Text & "','" & TxtDescription.Text & "','" & TxtAmount.Text & "', '" & TxtSCode.Text & "', '" & TxtCheque.Text & "', '" & "', '" & "')"
                .ExecuteNonQuery()
            End With

            TxtInvoice.Clear()
            TxtDate.Clear()
            TxtSupplier.Clear()
            TxtDescription.Clear()
            TxtAmount.Clear()
            TxtSCode.Clear()
            TxtCheque.Clear()
            cn.Close()

            MsgBox("Successfully", MsgBoxStyle.Information, Text)

        End Sub

    Hoping your valuable response.

    Thanks a lot in advance.

    Sunday, June 28, 2015 12:46 PM