3
I wanted to have a table of select commands in the bank, and they were read in a combobox. I have a textbox where I write the command to be executed by the bank, a button for it and a combobox with recorded commands. When the command I want to execute is not in the combobox, I type. And I wanted it to be saved to be read in the combobox if it didn’t exist. I did so:
public OracleDataReader VerificarComandoExistente(string descricao)
{
strQuery = "select * from comando where comando = '" + descricao + "' ";
return ObjBancoDados.RetornaDataReader(strQuery);
}
In C# it does not accept this way when I put a command with Where where it has to have the quotes. Ex select * from all_tables Where Owner ='hr' . Does not read hr.
In the bank I made the test, exchanging '' for "". Ran normal in sqldeveloper, but not in c#.
Summarizing. The system has to receive the code, check in the bank if it exists, and save in the table if it does not exist.
Look I understood what is happening. I make a simple select and the result goes to datagridview:
" select * from all_tables Where Owner = 'HR' "
After you have done this if this command is not in the bank, it will need to be saved. Hence a different select:
" select command from command Where command ='select * from all_tables Where Owner ='HR' ' "
The second select runs after the first
The problem is that single quotes work in the first command and in the second command have to be double quotes for Oracle to recognize (works directly in Oracle) It would have to be something like the Replace method, only I don’t think you can quote...
None of the solutions worked
how I would make the complete code, I don’t know because I was taught wrong. Adapter = Oracle.DataAccess.Client
– Marcus Vinicius
@Marcusvinicius, it’s exactly the way I put it in the answer, but to make it easier I put a complete method as an example and improved some points of the answer for you to try to correct your code.
– George Wurthmann
sorry but did not understand the 'db' above, is not stated...
– Marcus Vinicius
@Marcusvinicius, in the first example I put only a snippet. db is an Oracleconnection object that in the second example is named "Conn".
– George Wurthmann