muchas gracias compañeros por fin me salio aki les dejo el code por si alguien lo necesita
Formulario
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace nab
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnmostrar_Click(object sender, EventArgs e)
{
MySqlConnection cnn
= new MySqlConnection
(); MySqlCommand cmd
= new MySqlCommand
(); MySqlDataAdapter da
= new MySqlDataAdapter
("Select * from cliente", cnn
); DataSet ds
= new DataSet
(); try
{
cnn.ConnectionString = "host=localhost;Uid=root;DataBase=clientes;port=3306";
cmd.CommandText = "Select * from cliente";
cmd.CommandType = CommandType.Text;
cmd.Connection = cnn;
cnn.Open();
da.Fill(ds, "cliente");
cmd.ExecuteReader();
dvgdatos.DataSource = ds.Tables[0];
cnn.Close();
}
catch (Exception n)
{
MessageBox.Show(n.HelpLink);
}
}
private void button1_Click_1(object sender, EventArgs e)
{
MySqlConnection cnn
= new MySqlConnection
(); MySqlCommand cmd
= new MySqlCommand
(); cnn.ConnectionString = "host=localhost;Uid=root;DataBase=clientes;port=3306";
try
{
cnn.Open();
cmd.CommandText = "insert into cliente(idcliente,nombre,apellidos,direccion,telefono)Values('"+Convert.ToInt32(txtclave.Text)+"','" + txtnombre.Text + "','" + txtapellidos.Text + "','" + txtdireccion.Text + "','" + Convert.ToInt32(txttelefono.Text) + "')";
cmd.Connection = cnn;
int contenedor = cmd.ExecuteNonQuery();
cnn.Close();
MessageBox.Show("Se ha registrado correctamente", "Registro exitoso", MessageBoxButtons.OK);
}
catch (Exception mesange)
{
MessageBox.Show(mesange.Message);
}
}
private void button4_Click(object sender, EventArgs e)
{
txtclave.Text = "";
txtapellidos.Text = "";
txtdireccion.Text = "";
txtnombre.Text = "";
txttelefono.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
MySqlConnection cnn
= new MySqlConnection
(); cnn.ConnectionString = "host=localhost;Uid=root;DataBase=clientes;port=3306";
cnn.Open();
MySqlCommand cmd
= new MySqlCommand
("Delete from cliente where idcliente=?idcliente"); try
{
cmd.Parameters.Add("?idcliente", MySqlDbType.Int32).Value = txtclave.Text;
cmd.Connection = cnn;
cmd.ExecuteNonQuery();
cnn.Close();
}
catch (Exception m)
{
MessageBox.Show(m.Message,("Por favor introduzca la clave del cliente"));
}
}
private void btnactualizar_Click(object sender, EventArgs e)
{
MySqlConnection cnn
= new MySqlConnection
(); cnn.ConnectionString = "host=localhost;Uid=root;Database=clientes;Port=3306";
cnn.Open();
MySqlCommand cmd
= new MySqlCommand
("Update cliente set nombre=?nombre,apellidos=?apellidos,direccion=?direccion,telefono=?telefono where idcliente=?idcliente"); try
{
cmd.Parameters.Add("?idcliente", MySqlDbType.Int32).Value = txtclave.Text;
cmd.Parameters.Add("?nombre", MySqlDbType.String).Value=txtnombre.Text;
cmd.Parameters.Add("?apellidos", MySqlDbType.String).Value = txtapellidos.Text;
cmd.Parameters.Add("?direccion", MySqlDbType.String).Value = txtdireccion.Text;
cmd.Parameters.Add("?telefono", MySqlDbType.Int32).Value = txttelefono.Text;
cmd.Connection = cnn;
cmd.ExecuteNonQuery();
}
catch (Exception m)
{
MessageBox.Show(m.Message);
}
}
}
}
saludos