Guest User

Untitled

a guest
Dec 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. public void Registrar()
  2. {
  3. string sql = string.Format("Insert into Persona (Nombre, ApPaterno, ApMaterno, FechaNac, Documento, Direccion, Telefono, Sexo, Email)
  4. values('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}')", this.Nombre, this.ApPaterno, this.ApMaterno, this.FechaNac, this.Documento, this.Direccion, this.Telefono, this.Sexo, this.Email);
  5. //("Insert into Cliente(Id, codigo, TipoCliente) values({0})", this.ID, this.codigo, this.TipoCliente)
  6.  
  7. Conexion.EjecutarComando(sql);
  8. }
  9.  
  10. create table Persona(
  11. Id int not null identity(1,1),
  12. Nombre varchar(50) not null,
  13. ApPaterno varchar(50),
  14. ApMaterno varchar(50),
  15. FechaNac date not null,
  16. Documento varchar(20) not null,
  17. Direccion varchar(50),
  18. Telefono varchar(20),
  19. Sexo varchar(20) not null,
  20. Email varchar(50),
  21. constraint pk_persona primary key(Id),
  22. )
  23.  
  24. create table TipoCliente(
  25. Id int identity(1,1) not null,
  26. Nombre varchar(50) not null,
  27. constraint pk_TipoCliente primary key(Id),
  28. )
  29.  
  30. create table Cliente(
  31. Id int not null,
  32. codigo int not null,
  33. TipoCliente int not null,
  34. constraint pk_cliente primary key(Id),
  35. constraint fk_persona_Cliente foreign key(Id)
  36. references Persona(Id) on delete cascade on update cascade,
  37. constraint fk_Cliente_TipoCliente foreign key(TipoCliente)
  38. references TipoCliente(Id) on delete cascade on update cascade
  39. )
  40.  
  41. public void Registrar()
  42. {
  43. using (SqlConnection conn = new SqlConnection("connection string"))
  44. {
  45.  
  46. string sql = @"Insert into Persona (Nombre, ApPaterno, ApMaterno,
  47. FechaNac, Documento, Direccion, Telefono, Sexo, Email)
  48. values(@nombre, @ApPaterno, @ApMaterno, ...)";
  49.  
  50. SqlCommand cmd = new SqlCommand(sql, conn);
  51. cmd.Parameters.AddWithValue("@nombre", this.Nombre);
  52. cmd.Parameters.AddWithValue("@ApPaterno", this.ApPaterno);
  53. cmd.Parameters.AddWithValue("@ApMaterno", this.ApMaterno);
  54. .
  55. .
  56.  
  57. cmd.ExecuteNonQuery();
  58. }
  59. }
Add Comment
Please, Sign In to add comment