1. Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as:

    All that and more! Registration is quick, simple and absolutely free. Join our community today!

Help Username Already Exists VB.NET MS Access

Discussion in 'Coding, Programming' started by fakeuser101, Mar 21, 2015.

  1. Sino pong programmer dito?

    please, paano po malalaman kung username already exists? di kasi gumagana yung codes na nasi-search ko. :(

    If btnSave.Text = "Save" Then
    Dim ct1 As String = "SELECT [Username] FROM tblCredentials WHERE Username='" & txtUsername.Text & "'"
    cmd = New OleDb.OleDbCommand(ct1)
    cmd.Connection = cnn
    rdr = cmd.ExecuteReader()

    If rdr.Read Then
    MessageBox.Show("Username already exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
    txtUsername.SelectAll()
    txtUsername.Focus()
    If Not rdr Is Nothing Then
    rdr.Close()
    End If
    Exit Sub
    End If
    End If


    If Me.txtMID.Tag & "" = "" Then

    'add data to table
    cmd.CommandText = "INSERT INTO [tblCredentials]([MemberID], [FirstName], [MiddleName], [LastName], [Address], [Username], [Password], [ConfirmPass], [Position]) " & _
    " VALUES(" & Trim(Me.txtMID.Text) & ",'" & Trim(Me.txtFirst.Text) & "','" & Trim(Me.txtMiddle.Text) & "','" & Trim(Me.txtLast.Text) & "','" & Trim(Me.txtAddress.Text) & "','" & Trim(Me.txtUsername.Text) & "','" & _
    Trim(Me.txtPass.Text) & "','" & Me.txtConfirmPass.Text & "','" & _
    Me.cboPosition.Text & "')"
    cmd.ExecuteNonQuery()
     
  2. If btnSave.Text = "Save" Then
    Dim ct1 As String = "SELECT [Username] FROM tblCredentials WHERE Username='" & txtUsername.Text & "'"
    cmd = New OleDb.OleDbCommand(ct1)
    cmd.Connection = cnn
    rdr = cmd.ExecuteReader()


    Answer :


    Dim querystr asString="SELECT Count(Username) FROM tblCredentials WHERE Username='" & txtUsername.Text & "'"
    Dim mycmd AsNew SqlCommand(querystr, Yourconnection)
    Dimvalue asObject= mycmd.ExecuteScalar()

    IF asObject > 0 THEN
    MsgBox("Existing")
    ELSE
    "Your Script"
    END IF
     
Tags / Keywords: