SQL Server - Comillas simples en SQL Server

Written by lopezatienza on 13 Noviembre 2008 – 9:49 -


Al intentar hacer un Insert o un Update en una tabla en SQL Server, te salta un error sin venir a cuento.

Si algún campo de la Query contiene comillas simples, antes de grabar debes hacer un replace(Campo, "'", "''")

Hay que reemplazar la comilla simple por dos, así almacenará el dato con una única comilla.


Tags:
Posted in SQL Server | No Comments »

CSharp - Enviar un Correo en C#

Written by lopezatienza on 12 Noviembre 2008 – 16:59 -

System.Net.Mail.MailMessage correo = new System.Net.Mail.MailMessage();

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();

try

{

correo.From = new System.Net.Mail.MailAddress("direccion de correo origen");

correo.To.Add("direccion correo destino (para poner varios hay que ponerlos separados por comas)");


correo.CC.Add("direccion correo para Copia (CC)");

correo.Bcc.Add("direccion correo para Copia oculta (CCO)");

correo.Subject = "Prueba de correo";

correo.Body = "\n\nFecha y hora GMT: " + DateTime.Now.ToUniversalTime().ToString("dd/MM/yyyy HH:mm:ss");

correo.IsBodyHtml = false;

correo.Priority = System.Net.Mail.MailPriority.Normal; // Prioridad

smtp.Host = "IP/Nombre del host";

smtp.Credentials = new System.Net.NetworkCredential("usuario", "password");

smtp.EnableSsl = false;

}

catch

{ }

More...

try

{

  smtp.Send(correo);

}

catch

{ }

 

Aquí os enseño otra forma de hacerlo:

MailMessage miCorreo = new MailMessage();

try

{

miCorreo.From = "Correo que quieres que aparezca como remitente";

miCorreo.Subject = "Cabecera del correo";

miCorreo.Body = "Texto del correo";

miCorreo.BodyFormat = MailFormat.Text;

miCorreo.Priority = MailPriority.Normal;                      

miCorreo.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = "Servidor POP";

miCorreo.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 25;

miCorreo.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;

miCorreo.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;

miCorreo.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "tucorreo@dominio.es";

miCorreo.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "Contraseña";

SmtpMail.SmtpServer = "Servidor POP";

miCorreo.To = "Correo al que se envía";

SmtpMail.Send(miCorreo);

}

catch (Exception ex)

{

General.MsgError(ex.Message + "\nAl enviar correo : " + Texto_Correo + " a: " + miCorreo.To, "EnviarCorreo");

return false;

}


Tags: ,
Posted in CSharp | No Comments »

CSharp - Conexion Dial-up en C#

Written by lopezatienza on 12 Noviembre 2008 – 11:30 -

Primeramente crearemos una clase llamada RAS con el siguiente código:

using System;

using System.Runtime.InteropServices;

 ///

/// Descripción breve de RAS.

///

// Clase comunicaciones REMOTAS

 public class RAS

{

    [DllImport("coredll.dll", CharSet = CharSet.Unicode)]

    private static extern int RasDial(int dialExtensions, int phoneBookPath, IntPtr rasDialParam, int NotifierType, int notifier, ref int hRasConn);

 

    [DllImport("coredll.dll", CharSet = CharSet.Unicode)]

    private static extern int RasHangUp(int hRasConn);

  Read more »


Tags: , ,
Posted in CSharp, WindowsCE | 2 Comments »
RSS