Hi
I have written a windows forms application that connects tosql server compact3.5 database. I store my usernames and passwords in the database. If I delete a username in the database via the application it does delete it, but I have to close the application and restart it, otherwise you can still use the username to log in.

Whats the problem here and how can I solve it?

if (result == DialogResult.Yes)
            {
                if (results >0)
                {
                    userDataTableAdapter.DeleteQuery(comboBox2.Text);
                    userDataTableAdapter.Update(spitKeyDataBaseDataSet3.UserData);
                    clearboxes();
                }

Are you storing the logged in username somewhere, I mean in any variable? Do remember to clear the cache.

No I don't store it in a variable. How do you clear the cache in C#?. Could only find code for browsers and ASP.net. Mine is a windows form application and cache.clear(); does not exist.

Thanks

This has nothing to do with cache. Always when you do a login, you have to check for the user`s userName and password. And if the database is empty (that means that the userName and passowrd do not exist in the database), user cannot log in. As simpe as that. You have a wrong code somewhere - you better check it out 1st before you wade into deeper problems.
PS: if you still have issues, can you please post a code in here - all of then regarding login.

Regards,
Mitja

here is the complete login code

private void btnLogin_Click(object sender, EventArgs e)
        {
            username = txtLogUser.Text;
            string searchFor = txtLogUser.Text;
            int results = 0;
            DataRow[] returnedRows;
            returnedRows = spitKeyDataBaseDataSet3.Tables["UserData"].Select("UserName='" + searchFor + "'");

            results = returnedRows.Length;

            if (results > 0)
            {
                //add code to evaluate user and pass
                dr1 = returnedRows[0];

                if (txtLogPass.Text == dr1[1].ToString())
                {
                    groupBox2.Visible = true;
                    groupBox3.Visible = true;
                    clearboxes();

                    if (dr1[3].ToString() == "1")
                    {
                        groupBox4.Visible = true;
                        comboBox1.Enabled = false;
                        groupBox5.Visible = true;
                        clearboxes();
                    }
                    else
                    {
                        groupBox4.Visible = false;
                        comboBox1.Enabled = true;
                        groupBox5.Visible = false;
                        clearboxes();
                    }

                    if (dr1[4].ToString() == "1")
                    {
                        btnGenerate.Enabled = true;
                        clearboxes();
                    }
                    else
                    {
                        btnGenerate.Enabled = false;
                        clearboxes();
                    }

                    if (dr1[2].ToString() == "1")
                    {
                        key1TextBox.Visible = true;
                        key2TextBox.Visible = true;
                        key3TextBox.Visible = true;
                        key4TextBox.Visible = true;
                        key5TextBox.Visible = true;
                        key6TextBox.Visible = true;
                        key7TextBox.Visible = true;
                        key8TextBox.Visible = true;
                        key9TextBox.Visible = true;
                        key10TextBox.Visible = true;
                        clearboxes();
                    }
                    else
                    {
                        key1TextBox.Visible = true;
                        key2TextBox.Visible = false;
                        key3TextBox.Visible = false;
                        key4TextBox.Visible = false;
                        key5TextBox.Visible = false;
                        key6TextBox.Visible = false;
                        key7TextBox.Visible = false;
                        key8TextBox.Visible = false;
                        key9TextBox.Visible = false;
                        key10TextBox.Visible = false;
                        clearboxes();
                    }
                }
                else
                {
                    MessageBox.Show("Invalid User name or Password");
                }
            }
            else
            {
                MessageBox.Show("Invalid User name or Password");
            }


        }
Be a part of the DaniWeb community

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