Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to create a login form, the username and password are stored in Database access, I tried it but it failed


What I have tried:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ComboBox1.Items.Clear() <--This line is always pointed
        PasswordTextBox.Clear()

        Dim ctr, i As Integer
        ds.Clear()
        If cn.State = ConnectionState.Open Then
            cn.Close()
        End If
        Module1.conn()
        cn.Open()
        str = "select * from Users"
        cmd = New OleDbCommand(str, cn)
        da.SelectCommand = cmd
        da.Fill(ds, "Users")
        ctr = ds.Tables("Users").Rows.Count - 1
        For i = 0 To ctr
            ComboBox1.Items.Add(ds.Tables("Users").Rows(i)(1).ToString)
        Next

    End Sub
Posted
Updated 12-Nov-20 6:00am
Comments
Richard Deeming 12-Nov-20 12:17pm    

1 solution

Until you have not defined a datasoruce for the combobox, you cannot clear it.


For now, before clearing the Items in combobx, set its DataSource to null
VB
ComboBox1.DataSource =  Nothing;
ComboBox1.Items.Clear();
 
Share this answer
 
v3
Comments
Member 14991233 13-Nov-20 1:35am    
there is no null in 'ComboBox1.DataSource = '
Sandeep Mewara 13-Nov-20 6:43am    
Apologies. It's nil in vb
Richard Deeming 13-Nov-20 6:47am    
It's Nothing in VB. :)
Sandeep Mewara 13-Nov-20 9:51am    
Thanks! I am clearly thinking something else.
Richard MacCutchan 13-Nov-20 8:00am    
Isn't that SmallTalk?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900