I'm having a question in C # and in SQL commands, I'm currently using SQLite as the local database. In my application I make the insertion of records in the Database, so far so good, but I was wondering if there is any way to return the command that was executed, in the form of a string, for example:
This is the method of receiving the parameters:
public void Inserir(Curso curso)
{
acessoaoDB.LimparParametros();
acessoaoDB.AdicionarParametros("@NomeCurso", curso.NomeCurso);
acessoaoDB.AdicionarParametros("@SiglaCurso", curso.SiglaCurso);
acessoaoDB.AdicionarParametros("@Descricao", curso.Descricao);
acessoaoDB.ExecutarManipulacao(CommandType.Text, "INSERT INTO cursos (nome_curso,sigla_curso,descricao) VALUES (@NomeCurso,@SiglaCurso,@Descricao)");
}
This is the method of inserting data into the table:
public void ExecutarManipulacao(CommandType commandType, string SQL)
{
SQLiteConnection sqlConnection = CriarConexao();
sqlConnection.Open();
SQLiteCommand sqlCommand = sqlConnection.CreateCommand();
sqlCommand.CommandType = commandType;
sqlCommand.CommandText = SQL;
sqlCommand.CommandTimeout = 7200;
foreach (SQLiteParameter sqliteParameter in sqliteParameterCollection)
{
sqlCommand.Parameters.Add(new SQLiteParameter(sqliteParameter.ParameterName, sqliteParameter.Value));
}
sqlCommand.ExecuteNonQuery();
}
What I wanted to do would be that after running the command, it would catch it the way it was sent to the bank, for example:
Command with variables:
"INSERT INTO cursos (nome_curso,sigla_curso,descricao) VALUES (@NomeCurso,@SiglaCurso,@Descricao)"
Command as I wanted it to be captured:
"INSERT INTO cursos (nome_curso,sigla_curso,descricao) VALUES ('Matematica','MAT123','Curso de Matematica do Ensino Medio')"
Thank you very much for your attention!