Tema: Duda en C#
Ver Mensaje Individual
  #12 (permalink)  
Antiguo 15/06/2009, 11:44
kutulay
 
Fecha de Ingreso: mayo-2009
Mensajes: 118
Antigüedad: 15 años
Puntos: 1
Respuesta: Duda en C#

Esto es lo que tengo de codigo:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace Busqueda_de_O.F
{
class ClsUtil
{

public static void SoloNumeros(object sender, KeyPressEventArgs e)
{

if ((e.KeyChar >= 48) && (e.KeyChar <= 57))
e.Handled = false;
//Acepta Borrador y Enter
else if ((e.KeyChar == 8) || (e.KeyChar == 13))
e.Handled = false;
else
{
e.Handled = true;
}

}

}




public partial class Form1 : Form
{
private DataSet bdl;//DataSet de datos
private DataTable tabla;//Tabla que almacena datos
private MySqlDataAdapter adaptador;//Objeto que sirve para comunicar al dataset con el DBMS
private MySqlConnection conn;//Objeto que realiza la conexion con el DBMS
private MySqlCommand cmd;//Objeto para la ejecucion de sentencias SQ


public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
bdl = new DataSet("singularity");
tabla = new DataTable("eventrecord");
conn = new MySqlConnection("Database=singularity;Data Source=localhost;User Id=root;Password=825200");
cmd = new MySqlCommand("Sentencia SQL", conn);
adaptador = new MySqlDataAdapter(cmd);
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
ClsUtil.SoloNumeros(textBox1, e);// con esto ya tendriamos la verificacion de solo numeros
}


string Codigo;
private void button1_Click(object sender, EventArgs e)
{
Codigo = textBox1.Text.Trim();
conn.Open();//Abre la conexion
if (bdl.Tables.Count == 0)
{

cmd.CommandText = " SELECT readerid FROM eventrecord WHERE tagid like '"+ Codigo +"%' ";
adaptador.Fill(tabla);
bdl.Tables.Add(tabla);

}

else
{

bdl.AcceptChanges();
adaptador.Update(bdl, "eventrecord");

}

dataGridView1.DataSource = bdl.Tables["eventrecord"];
dataGridView1.Update();
conn.Close();//Cierra la conexion

this.dataGridView1.AllowUserToAddRows = false;
textBox2.Text = dataGridView1.Rows.Count.ToString();
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

try
{
bdl = new DataSet("singularity");
tabla = new DataTable("eventrecord");
conn = new MySqlConnection("Database=singularity;Data Source=localhost;User Id=root;Password=825200");
cmd = new MySqlCommand("Sentencia SQL", conn);
adaptador = new MySqlDataAdapter(cmd);
}

catch (MySqlException ex)
{
MessageBox.Show(ex.Message, "Error al intentar conectarse", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}

private void button2_Click(object sender, EventArgs e)
{
this.textBox1.Text ="";
this.textBox2.Text = "";
dataGridView1.DataSource = null;
}
}
}