I have a database in Access in which there are 2 fields called Base de Datos
and another one called Tipo de Usuario
. I would like that when selecting an item in the combobox, the type of user that it is appears in the textbox of Tipo de Usuario
. There are 2 possible Administrator or User options. I understand a little the logic that I must use, the code that I use is the following but it throws me an error, which says that some parameters are missing, which I can not understand what it refers to. Beforehand, thank you.
private void base_de_DatosComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
OleDbConnection cnx = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\BD_Usuarios.accdb");
try
{
cnx.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = cnx;
string query = "select * from Usuarios where Tipo_de_Usuario='"+base_de_DatosComboBox.Text+"';";
command.CommandText = query;
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
tipo_de_UsuarioTextBox.Text = reader["Tipo de Usuario"].ToString();
}
cnx.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex);
}
}
I enclose a photo of the error: