Skip to main content
adicionou 126 caracteres ao conteúdo
Fonte Link
rray
  • 67,7mil
  • 21
  • 116
  • 285

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();
}

}

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();

}

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();
}
Fonte Link
user2254936
  • 305
  • 2
  • 5
  • 13

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();

}