Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Registrar()
- {
- string sql = string.Format("Insert into Persona (Nombre, ApPaterno, ApMaterno, FechaNac, Documento, Direccion, Telefono, Sexo, Email)
- 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);
- //("Insert into Cliente(Id, codigo, TipoCliente) values({0})", this.ID, this.codigo, this.TipoCliente)
- Conexion.EjecutarComando(sql);
- }
- create table Persona(
- Id int not null identity(1,1),
- Nombre varchar(50) not null,
- ApPaterno varchar(50),
- ApMaterno varchar(50),
- FechaNac date not null,
- Documento varchar(20) not null,
- Direccion varchar(50),
- Telefono varchar(20),
- Sexo varchar(20) not null,
- Email varchar(50),
- constraint pk_persona primary key(Id),
- )
- create table TipoCliente(
- Id int identity(1,1) not null,
- Nombre varchar(50) not null,
- constraint pk_TipoCliente primary key(Id),
- )
- create table Cliente(
- Id int not null,
- codigo int not null,
- TipoCliente int not null,
- constraint pk_cliente primary key(Id),
- constraint fk_persona_Cliente foreign key(Id)
- references Persona(Id) on delete cascade on update cascade,
- constraint fk_Cliente_TipoCliente foreign key(TipoCliente)
- references TipoCliente(Id) on delete cascade on update cascade
- )
- public void Registrar()
- {
- using (SqlConnection conn = new SqlConnection("connection string"))
- {
- string sql = @"Insert into Persona (Nombre, ApPaterno, ApMaterno,
- FechaNac, Documento, Direccion, Telefono, Sexo, Email)
- values(@nombre, @ApPaterno, @ApMaterno, ...)";
- SqlCommand cmd = new SqlCommand(sql, conn);
- cmd.Parameters.AddWithValue("@nombre", this.Nombre);
- cmd.Parameters.AddWithValue("@ApPaterno", this.ApPaterno);
- cmd.Parameters.AddWithValue("@ApMaterno", this.ApMaterno);
- .
- .
- cmd.ExecuteNonQuery();
- }
- }
Add Comment
Please, Sign In to add comment