Torna al Thread
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Data;
using System.Data.OleDb;
namespace odceccatanzaro.it
{
public partial class ml : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.Click += new EventHandler(this.Button1_Click);
}
protected void Button1_Click(object sender, EventArgs e)
{
String str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("/App_Data/mailing_list.mdb");
OleDbConnection cn = new OleDbConnection(str);
cn.Open();
string nome = this.TextBox1.Text;
string mail = this.TextBox2.Text;
string stato = "";
if (this.RadioButtonList1.SelectedValue.Equals("Iscriviti"))
{
stato = "si";
try
{
string sql = "INSERT INTO lista (nome,email,attivo,data_inserimento) VALUES (@nome,@mail,@attivo,@data_inserimento)";
OleDbCommand cmd = new OleDbCommand(sql, cn);
cmd.Parameters.Add(new OleDbParameter("@nome", nome));
cmd.Parameters.Add(new OleDbParameter("@mail", mail));
cmd.Parameters.Add(new OleDbParameter("@attivo", stato));
OleDbParameter parameter = new OleDbParameter("@data_inserimento", OleDbType.Date);
parameter.Value = System.DateTime.Now;
cmd.Parameters.Add(parameter);
cmd.ExecuteNonQuery();
this.verifica_ml.ForeColor = System.Drawing.Color.Green;
this.verifica_ml.Text = "Email inserita";
}
catch (Exception ex)
{
this.verifica_ml.ForeColor = System.Drawing.Color.Red;
this.verifica_ml.Text = "Si è verificato un errore, riprova in seguito!";
}
}
if (this.RadioButtonList1.SelectedIndex.Equals("Cancellati"))
{
try
{
this.verifica_ml.ForeColor = System.Drawing.Color.Green;
this.verifica_ml.Text = "Cancellazione eseguita";
}
catch (Exception ex)
{
this.verifica_ml.ForeColor = System.Drawing.Color.Red;
this.verifica_ml.Text = "Si è verificato un errore, riprova in seguito!";
}
}
cn.Close();
}
}
}