I'm with a project that stores documents, My question is how can I store them and that SQL tell me if the document with the same name or ID exists.
This is the SQL code:
USE [HConDe]
GO
/****** Object: StoredProcedure [dbo].[ActualizarDocumento] Script Date: 11/09/2018 10:54:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[ActualizarDocumento]
@iddocu int, @nomdocu varchar(50), @fechadocu date, @contdocu varchar(max)
as
--ActualizarDocumento
if not exists (SELECT id_documento from Documento where id_documento=@iddocu)
insert into Documento (id_documento,nombre_documento,fecha_documento,contenido_documento) values (@iddocu, @nomdocu , @fechadocu, @contdocu)
else print 'Archivo existe'
In C # I execute it. The problem is that I replaced the file without any dialogue before. I wanted to know how I could do it ..
public override bool Guardar()
{
try {
string cmd = String.Format("EXEC ActualizarDocumento '{0}','{1}','{2}','{3}'", txtiddocu.Text.Trim(), txtDocu.Text.Trim(), dt1.Value.ToString(), rich.Trim());
utlidades.Ejecutar(cmd);
MessageBox.Show("Se ha guardado correctamente");
return true;
}
catch(Exception error) {
MessageBox.Show("Se ha producido un error: " + error.Message);
return false;
}
}