Visual Basic - Problema con evitar Datos repetidor

Life is soft - evento anual de software empresarial
 
Vista:

Problema con evitar Datos repetidor

Publicado por Vania (1 intervención) el 03/06/2020 19:11:26
Hola, tengo este codigo para agregar informacion sobre alumnos a una base de datos en excel, alguien me podria ayudar para ver de que manera agregar un codigo que evite que ingrese datos duplicados en el campo "Mat"





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Imports System.Data.OleDb
 
Public Class Agregar
    Dim cn As New OleDbConnection
    Dim cm As New OleDbCommand
    Sub playbackgroundsoundfile()
        My.Computer.Audio.Play("C:\archivos\sound.wav",
                       AudioPlayMode.Background)
    End Sub
 
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 
        Dim mat, nom, sex, dom, tel, car As String
        Dim mus, cin, dep, tea, act As Integer
 
 
        mat = TextBox1.Text
        nom = TextBox2.Text
 
        If RadioButton1.Checked = True Then
            sex = "Femenino"
        End If
        If RadioButton2.Checked = True Then
            sex = "Masculino"
        End If
        If RadioButton3.Checked = True Then
            sex = "Indiferente"
        End If
 
        dom = TextBox3.Text
        tel = TextBox4.Text
        car = ComboBox1.Text
 
        If CheckBox1.Checked = True Then
            mus = 1
        Else
            mus = 0
        End If
        If CheckBox2.Checked = True Then
            cin = 1
        Else
            cin = 0
        End If
        If CheckBox3.Checked = True Then
            dep = 1
        Else
            dep = 0
        End If
        If CheckBox4.Checked = True Then
            tea = 1
        Else
            tea = 0
        End If
 
        act = 1
 
        If mat.Equals("") = False And nom.Equals("") = False And dom.Equals("") = False And tel.Equals("") = False And ComboBox1.Text <> "-Selecciona una Carrera-" Then
 
 
            cn.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source= C:\Archivos\Escolar4.xls;extended properties=excel 8.0;"
            cn.Open()
 
            cm.Connection = cn
            cm.CommandText = "insert into [Sheet1$]values('" & mat & "','" & nom & "','" & sex & "','" & dom & "','" & tel & "','" & car & "','" & mus & "','" & cin & "','" & tea & "','" & dep & "','" & act & "')"
            cm.ExecuteNonQuery()
            cn.Close()
 
            MsgBox("Informacion guardada")
 
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
            ComboBox1.Text = "-Selecciona una Carrera-"
            CheckBox1.Checked = False
            CheckBox2.Checked = False
            CheckBox3.Checked = False
            CheckBox4.Checked = False
        Else
            playbackgroundsoundfile()
            MsgBox("No se puede guardar existen campos vacios")
 
 
 
        End If
 
    End Sub
End Class
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder