0

Validate student id,username if already exist in database table . Using VB.Net 2012 and SQL database on windows10 system. Thanks for your help.this is my first post so thank you for your help guys.

 Private Sub InsertSutdent()
    SQL.AddParam("@stud_name", txtFirstname.Text)
    SQL.AddParam("@stud_lastname", txtlastname.Text)
    SQL.AddParam("@stud_id", txtStudentId.Text)
    SQL.AddParam("@stud_username", txtUsername.Text)
    SQL.AddParam("@stud_course", cbxCourse.Text)
    SQL.AddParam("@stud_password", txtpassword.Text)
    SQL.AddParam("@active", Status.Checked)

        SQL.ExecQuery("INSERT INTO Student (Stud_Firstname,Stud_Lastname,Stud_idnum,Stud_Password,Stud_Course,JoinDate,Stud_Username,Active) " & _
                    "VALUES (@stud_name,@stud_lastname,@stud_id,@stud_password,@stud_course,GETDATE(),@stud_username,@active);", True)

        If SQL.HasException(True) Then Exit Sub

        If SQL.DBDT.Rows.Count > 0 Then
            Dim r As DataRow = SQL.DBDT.Rows(0)

            regrow.Text = (r("LastID").ToString)

        End If
        indicator.Text = "Added!"

        LoadStudent()
End Sub
2
Contributors
1
Reply
16
Views
6 Months
Discussion Span
Last Post by thines01
0

One way to do this is to attempt a SELECT on the desired record.
If it does not exist, you can perform the INSERT.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.