
17/06/2009, 10:11
|
| | Fecha de Ingreso: mayo-2007 Ubicación: PIC-16F84A
Mensajes: 729
Antigüedad: 17 años, 8 meses Puntos: 8 | |
Lectura y escritura sobre BD con Visual C# Hey:
Con estos datos y l abase de datos llamada prueba01 creamos la tabla.
Código:
CREATE TABLE `dispositivos` (
`ID` int(11) NOT NULL,
`nombre` varchar(30) NOT NULL,
`estado` tinyint(3) unsigned NOT NULL DEFAULT '0',
`descripcion` varchar(200) NOT NULL,
PRIMARY KEY (`ID`),
FULLTEXT KEY `nombre` (`nombre`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Luego insertamos estos datos.
Código:
--
-- Volcar la base de datos para la tabla `dispositivos`
--
INSERT INTO `dispositivos` (`ID`, `nombre`, `estado`, `descripcion`) VALUES
(1, 'RELE 1', 1, 'Motor 1'),
(2, 'RELE 2', 1, 'Motor 2'),
(3, 'RELE 3', 1, 'Alarma'),
(4, 'RELE 4', 1, 'WebCam');
Código:
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; // No olvidar este using.
using MySql.Data.Types; // No olvidar este using.
namespace MySQL06
{
public partial class Form1 : Form
{
MySqlConnection connection = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string MyConString = "SERVER=" + "127.0.0.1" + ";" +
"DATABASE=" + "prueba01" + ";" +
"UID=" + "Acaymo" + ";" +
"PASSWORD=" + "Metaconta2009" + ";";
connection = new MySqlConnection(MyConString);
connection.Open();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
connection.Close();
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
MySqlCommand command = connection.CreateCommand();
command.CommandText = "select * from dispositivos;";
MySqlDataReader Reader = command.ExecuteReader();
while (Reader.Read())
{
label1.Text = Convert.ToString(Reader["nombre"]);
//Reader.NextResult();
label2.Text = Convert.ToString(Reader["nombre"]);
//Reader.NextResult();
label3.Text = Convert.ToString(Reader["nombre"]);
//Reader.NextResult();
label4.Text = Convert.ToString(Reader["nombre"]);
//Reader.NextResult();
richTextBox1.Text = Reader.GetString(0);
richTextBox2.Text = Reader.GetString(1);
richTextBox3.Text = Reader.GetString(2);
richTextBox4.Text = Reader.GetString(3);
}
Reader.Close();
timer1.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
}
}
Con el código de arriba quiero conseguir el efecto de la imagen de abajo. No se el código necesario para conseguirlo. Al menos vamos a centrarnos en sólo lectura desde MySQL 5.1.
Debe mostrarse los datos como se muestra en la imagen y no se como hacerlo.
__________________ Meta Shell, VERSIÓN 1.2.2 Descargar |