sábado, 3 de diciembre de 2011

Visual_Estudio+Mysql+C#



using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data.MySqlClient;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void  Button1_Click(object sender, EventArgs e)
    {
        MySqlConnection cn = null;
        String strcn = null;
        strcn = "DataBase=scget; DataSource=localhost; User Id=root; Password=123456";
        cn = new MySqlConnection(strcn);
        cn.Open();
        string CommandText;
        CommandText = "select * from ENTIDAD_T";      
        MySqlDataAdapter cSeleccion = new MySqlDataAdapter(CommandText, cn);
        DataSet ds = new DataSet();
        cSeleccion.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string CadenaConexion = "DataBase=scget; DataSource=localhost; User Id=root; Password=123456";
        string CadenaActualizacion = "insert into ENTIDAD_T values (" + TextBox1.Text + "," + TextBox2.Text + ")";
        MySqlConnection dbconexion = new MySqlConnection(CadenaConexion);
        MySqlCommand Adicion = new MySqlCommand();
        Adicion.Connection = dbconexion;
        Adicion.CommandText = CadenaActualizacion;
        dbconexion.Open();
        Adicion.ExecuteNonQuery();
        dbconexion.Close();    
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        string CadenaConexion = "DataBase=scget; DataSource=localhost; User Id=root; Password=123456";
        string CadenaActualizacion = "update ENTIDAD_T set entnombre='" + TextBox2.Text + "' where entidadid='" + TextBox1.Text + "' ";
        MySqlConnection dbconexion = new MySqlConnection(CadenaConexion);
        MySqlCommand Adicion = new MySqlCommand();
        Adicion.Connection = dbconexion;
        Adicion.CommandText = CadenaActualizacion;
        dbconexion.Open();
        Adicion.ExecuteNonQuery();
        dbconexion.Close();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        string CadenaConexion = "DataBase=scget; DataSource=localhost; User Id=root; Password=123456";
        string CadenaActualizacion = "delete from ENTIDAD_T where entidadid='" + TextBox1.Text + "' ";
        MySqlConnection dbconexion = new MySqlConnection(CadenaConexion);
        MySqlCommand Adicion = new MySqlCommand();
        Adicion.Connection = dbconexion;
        Adicion.CommandText = CadenaActualizacion;
        dbconexion.Open();
        Adicion.ExecuteNonQuery();
        dbconexion.Close();
    }
}

No hay comentarios:

Publicar un comentario