Hi,

Let's say i have 2 boxes, 'UsernameComboBox' and 'PasswordTextBox' and a button, 'Update'. I would like the database (Access) to update a given record according to the values selected/input into the above 2 boxes. How do i go about doing this?

Any help will be greatly appreciated :)

You can do it with the help of OleDbCommand easily. Your code looks like below :

objCmd = new OleDbCommand();
objCmd.Connection = objCon;
objCmd.CommandText = "Update table1 Set username=@username, password=@password Where username=@uname";
objCmd.Parameters.AddWithValue("@username", combobox1.Text);
objCmd.Parameters.AddWithValue("@password", txtPassword.Text);
objCmd.Parameters.AddWithValue("@uname", combobox1.Text);
objCon.Open();
objCmd.ExecuteNonQuery();
objCon.Close();

Hi,

Let's say i have 2 boxes, 'UsernameComboBox' and 'PasswordTextBox' and a button, 'Update'. I would like the database (Access) to update a given record according to the values selected/input into the above 2 boxes. How do i go about doing this?

Any help will be greatly appreciated :)

You can do it with the help of OleDbCommand easily. Your code looks like below :

objCmd = new OleDbCommand();
objCmd.Connection = objCon;
objCmd.CommandText = "Update table1 Set username=@username, password=@password Where username=@uname";
objCmd.Parameters.AddWithValue("@username", combobox1.Text);
objCmd.Parameters.AddWithValue("@password", txtPassword.Text);
objCmd.Parameters.AddWithValue("@uname", combobox1.Text);
objCon.Open();
objCmd.ExecuteNonQuery();
objCon.Close();

Hi, thanks for the help. Doesn't seem to work, my codes are as follows:

private void UpdateButton_Click(object sender, EventArgs e)
        {
            DBconn = new OleDbConnection();
            DBconn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=DBTest.accdb;";

            objCmd = new OleDbCommand();
            objCmd.Connection = DBconn;
            objCmd.CommandText = "Update PC Set PCUsername=@username, PCPassword=@password Where PCName='PC001'";
            objCmd.Parameters.AddWithValue("@username", UsernameComboBox.Text);
            objCmd.Parameters.AddWithValue("@password", PasswordTextBox.Text);
            DBconn.Open();
            objCmd.ExecuteNonQuery();
            DBconn.Close();
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.