Ver Mensaje Individual
  #3 (permalink)  
Antiguo 24/05/2009, 14:02
kutulay
 
Fecha de Ingreso: mayo-2009
Mensajes: 118
Antigüedad: 15 años
Puntos: 1
Respuesta: Como asignar textbox a variable para buscar en Mysql

Hola Dradi7 a ver te cuento hice lo que me dijiste pero creo que no lo hice bien pq me da error al compilar.Voy a pegar aqui lo que hice para que me corrijas sobre la marcha :

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.MySqlClient;
using MySql.Data;

namespace Consulta3
{
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;
private DataTable tabla;
private MySqlDataAdapter adaptador;
private MySqlConnection conn;
private MySqlCommand cmd;



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 textBox_KeyPress(object sender, KeyPressEventArgs e)
{
ClsUtil.SoloNumeros(textBox, e);
}



int Codigo;

private void button1_Click(object sender, EventArgs e)
{
Codigo = int.Parse(textBox.Text.Trim());

conn.Open();//Abre la conexion
if (bdl.Tables.Count == 0)
{

cmd.CommandText = "SELECT readerId FROM eventrecord WHERE tagId='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


}

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);
}

}


}
}