Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Displaying data from an Access database to a TextBox control

I'm trying to get a data value from a database and display it into a TextBox and it is not working, can anyone help?

private void textBox1_TextChanged(object sender, EventArgs e)
{
    try
    {
        OleDbConnection Connection = new OleDbConnection(
            @"Provider=Microsoft.ACE.OLEDB.12.0;
            Data Source=C:\Users\john\Documents\\Projects\game\gamedb.accdb;Persist Security Info=False;"
    );
        OleDbCommand command = new OleDbCommand();
        command.Connection = connection;
        connection.Open();

        OleDbDataReader rd = command.ExecuteReader();
        string query = "SELECT FullName FROM ManUnited WHERE (ID=1)";
        command.CommandText = query;
        command.CommandType = CommandType.Text;
        command.Connection = connection;

        command.Parameters.AddWithValue("(ID=1)", textBox1);
        rd = command.ExecuteReader();
        connection.Close();
    }
    catch(Exception ex)

    {
        MessageBox.Show("Error" + ex);
    }
}

Comments