I have a combobox which is cboUser. In cboUser contains 5 item and have a aseparate password each user1="user1",user2="user2",user3="user3",admin1="admin1",admin2="admin2". All of the items have a password.If the user selects user 1 and the user input the password "user1". Then it goes to another form.

What is the code for that?

Advance thank you

Recommended Answers

All 3 Replies

In another form(frmSalesData), there will be a label in which it tracks the time the user login and another label in which it gets the user selected item in cboUser where the cboUser from(frmLogin)

Well you can try something like this assume that you have a textbox called txtPass where the user will enter his/her password

If cboUser.SelectedItem = "user1" And txtPass.Text = "user1" Then
frmSalesData.lblTime.Text = Time.Now ' not sure of this if Time.Now produce error try DateAndTime.Now.ToLong or something like that I'm not infront of a computer as I'm responding.
frmSalesData.lblUser.Text = cboUser.SelectedItem


If cboUser.SelectedItem = "user2" And txtPass.text = "user2" Then
' Do the same as above and continue with the remaining your self.
End If
End If

You can put these codes in a button event. As you can see you will have to do the rest the same way I did it but I didn't do it all due to time.

hye !

hope this code helps you

dim con as new sqlconnection("connection string")
dim da as new sqldataadapter("select username ,password from table",con)
cboUser.datasource = dt
cboUser.Displaymember = "username"
cboUser.Valuemember = "password"

' now we have two textboxes , txtUsername and txtPassword. and we want to set there values

'on selected index change event of the combo box , use this code.

txtUsername.text = cboUser.Selectedtext.tostring()
txtPassword.txt = cboUser.SelectedValue()


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.