
Unir dos consultas de BD Distintas
Publicado por Ruben Dario (23 intervenciones) el 24/05/2015 16:22:30
Buenas Tardes
Como puedo hacer para unir tablas de dos base de datos distintas en c#
Este es mi codigo
Saludos
Como puedo hacer para unir tablas de dos base de datos distintas en c#
Este es mi codigo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
private void frmpedidos_Load(object sender, EventArgs e)
{
try
{
// Se crea la conexión a la base de datos "TXGL"
MySqlConnection conectarbdtxgl = new MySqlConnection("server=192.168.2.5; database=txgl; Uid=root; pwd=Gl1721+; port=3305;");
// Se crea otra conexion para la base de datos "Gestion Pedidos"
MySqlConnection conectarbdgestion = new MySqlConnection("server=192.168.2.5; database=gestionpedido; Uid=root; pwd=Gl1721+; port=3305;");
//abrimos nuestra conexion
conectarbdtxgl.Open();
conectarbdgestion.Open();
//Creamos el comando para el select el @ ayuda a que se pueda escribir en varias lineas
MySqlCommand cmdtxgl = conectarbdtxgl.CreateCommand();
cmdtxgl.CommandText = @"Select p.id, p.pedidokey, p.riqi, p.fecha_c, p.kehuID, p.yewuyuanID, p.jinez, p.beizhu, v.bianhao, v.py, c.bianhao, c.name, c.shengfen, c.chengshi, c.youbian
from pedidolist p, kehu c, yewuyuan v
where p.yewuyuanID = v.bianhao and c.bianhao = p.kehuID
order by p.id desc";
MySqlCommand cmdgestion = conectarbdgestion.CreateCommand();
cmdgestion.CommandText = @"Select pedidokey, color, color2
from poee "; //where estado='P' or estado='C' or estado='I'
//Aqui es donde me pierdo y me gustaría saber que ahcer para unir
var q = @"select p.id, p.pedidokey, p.riqi, p.fecha_c, p.kehuID, p.name, p.yewuyuanID, p.py, p.jinez, p.beizhu, p.bianhao, p.shengfen, p.chengshi, p.youbian, po.color, po.color2
from cmdtxgl p
left JOIN cmdgestion ON p.pedidokey=cmdgestion.pedidokey ";
MySqlDataReader reader = cmdtxgl.ExecuteReader();
//Creamos un ciclo para llenar el data grid
while (reader.Read())
{
this.dgvpedidocabecera.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4),reader.GetValue(11));
}
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex.Message);
}
}
Saludos
Valora esta pregunta


0