OleDbConnection cnx = new OleDbConnection(new AdministradorDAO().conexao); cnx.Open();Estou com dificuldade para retornar meu ID usando o nextval, para posteriormente fazer o insert em minha tabela
OleDbConnection cnx = new OleDbConnection(new AdministradorDAO().conexao);
cnx.Open();
string seq = ("select id_usuarios.nextval from dual");
OleDbCommand cmdo = new OleDbCommand(seq, cnx);
int id= (int)cmdo.ExecuteScalar();
using (OleDbCommand cmd = cnx.CreateCommand())
{
// create command with placeholders
cmd.CommandText =
"INSERT INTO USUARIOS"+
"([ID], [MATRICULA], [NOME], [SENHA], [NIVEL]),[MALETA],[EMAIL]) "+
"VALUES(@id, @ma, @no, @se, @ni,@ma,@em)";
// add named parameters
cmd.Parameters.AddRange(new OleDbParameter[]
{
new OleDbParameter("@id", id),
new OleDbParameter("@ma", txt_matricula.Text),
new OleDbParameter("@no", txt_nome.Text),
new OleDbParameter("@se", txt_senha.Text),
new OleDbParameter("@ni", int.Parse(DropDownList_nivel.Text)),
new OleDbParameter("@ma", int.Parse(txt_maleta.Text)),
new OleDbParameter("@em", txt_email.Text),
});
cmd.ExecuteNonQuery();
}
}