Need join 2 datatables or 2 datagrids in the next picture like I show with the lines, but dont have any idea how do it cuz its my first time ussin C#, if some one can give some direcciton or some help I will thanks soo mush...
question how can I join 2 tables or datagrids
Page 1 of 19 Replies - 312 Views - Last Post: 05 October 2012 - 01:44 PM
Replies To: question how can I join 2 tables or datagrids
#2
Re: question how can I join 2 tables or datagrids
Posted 04 October 2012 - 01:47 PM
Your picture didn't make it through.
What do you mean by "join"? It can have different meaning in different contexts: database, UI, etc.
What do you mean by "join"? It can have different meaning in different contexts: database, UI, etc.
#3
Re: question how can I join 2 tables or datagrids
Posted 04 October 2012 - 01:51 PM
sorry my bad english. isnt my natal language, join like merge or union, getting rows form diferent data tables or datagrid, Im ussing dev express gridcontrol
#4
Re: question how can I join 2 tables or datagrids
Posted 04 October 2012 - 01:59 PM
This is the code I have for now
namespace Ardesa
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Declara la coneccion a base de datos Access por medio de la clase Conectar.cs
readonly Conectar Conec = new Conectar();
//Declara la coneccion a base de datos SQL por medio de la clase conectar2.cs
readonly conectar2 conecard = new conectar2();
private string Query;
private string Query2;
private void Cargar_Datos()
//Leer base de datos Access
{
try
{
//Despliega las entradas tipo entrada en en grid entrada
Conectar.Cerrar();
Conectar.Abrir();
dtMarcas.Tables[4].Clear();
using (OleDbDataAdapter Buscar = new OleDbDataAdapter("", Conectar.myconec))
{
Query = @" Select
UserID as ID,
CheckTime,
CheckType as tipoentrada
From
CheckInOut
Where
CheckType='I'
Order By
UserID,
CheckTime";
Buscar.SelectCommand.CommandText = Query;
Buscar.Fill(dtMarcas.Tables[4]);
}
Conectar.Cerrar();
//Despliega las marcas tipo salida en el grid salida
Conectar.Abrir();
dtMarcas.Tables[3].Clear();
using (OleDbDataAdapter Buscar = new OleDbDataAdapter("", Conectar.myconec))
{
Query = @" Select
UserID as ID,
CheckTime,
CheckType as tiposalida
From
CheckInOut
Where
CheckType='O'
Order By
UserID,
CheckTime";
Buscar.SelectCommand.CommandText = Query;
Buscar.Fill(dtMarcas.Tables[3]);
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
private void Cargar_sql()
//Leer base datas SQL
{
try
{
conectar2.Cerrar();
conectar2.Abrir();
dtMarcas.Tables[2].Clear();
using (SqlDataAdapter leer = new SqlDataAdapter("", conectar2.myconec))
{
Query2 = @"select NUM_PERSONAL as ID, NOMBRES + ' ' + APELLIDOS as Nombre from dbo.RH_FICHAEMP" ;
leer.SelectCommand.CommandText = Query2;
leer.Fill(dtMarcas.Tables[2]);
}
conectar2.Cerrar();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
//Ejecutar las funciones al cargar el formulario.
{
Cargar_sql();
Cargar_Datos();
}
private void btnAceptar_Click(object sender, EventArgs e)
//Reealiza los calculos y agrupaciones correspondientes.
{
dtMarcas.Tables[1].Clear();
int x = 0;
//int i = 0;
foreach (DataRow Dr in dtMarcas.Tables[4].Rows)
{
if (Dr["ID"].ToString() == txtCodigo.Text)
{
DataRow Row;
Row = dtMarcas.Tables[1].NewRow();
Row["Codigo"] = Dr["ID"].ToString();
for (int index = 0; index <= datospersonales.Row.Count - 1; index++)
{
Dr["ID"].ToString() = datospersonales.Row[index];
if (dtMarcas.Tables[2].Row[index]["ID"].toString() == Dr["ID"].ToString())
{
Row["Nombre"] = "NOMBRES";
}
}
if (Dr["tipoentrada"].ToString() == "I")
{Row["FechaIn"] = Dr["CheckTime"].ToString();}
else{Row["FechaOut"] = Dr["CheckTime"].ToString();
Row["Horas"] = 2;
dtMarcas.Tables[1].Rows.Add(Row);
gridCalculo.Refresh();
}
x++;
}
}
}
}
#5
Re: question how can I join 2 tables or datagrids
Posted 05 October 2012 - 04:47 AM
Which of those queries are you wanting to combine? What result are you looking for?
#6
Re: question how can I join 2 tables or datagrids
Posted 05 October 2012 - 07:54 AM
I have datatable1: ID, Name. datatable2: ID, checkin, typecheck datatable3: ID, checkout, typecheck
and I want like result union: ID, Nane, checkin, checkout, hour(CHECKOUT-CHEECKIN)
and I want like result union: ID, Nane, checkin, checkout, hour(CHECKOUT-CHEECKIN)
#7
Re: question how can I join 2 tables or datagrids
Posted 05 October 2012 - 08:02 AM
Okay, I'll ask a silly question: Why are you trying to do the joins from the client side using the DataTable's and/or the DataGridView's? In your code above, I see that you doing queries into a database. Why not do a query into the database with the appropriate join and put the results into the appropriate DataGridView?
Is there some kind of bandwidth limit or network latency issue? Or does your database not support joins? Or is there some kind of special filtering that happens on the client side that is not reflected in the database, so it's the data that is in the local tables/views are more relevant than what is really in the database?
Is there some kind of bandwidth limit or network latency issue? Or does your database not support joins? Or is there some kind of special filtering that happens on the client side that is not reflected in the database, so it's the data that is in the local tables/views are more relevant than what is really in the database?
#8
Re: question how can I join 2 tables or datagrids
Posted 05 October 2012 - 09:34 AM
the check clock use access data base, the empresse use sql in all they aplications, Im gettein the checkin and out from the access database and the name from the sql database, I need present all that data on one table and calcule the work hour for every one just opening the aplication, for use of the person who makes the pay to the employess.
If u seen the way to do it ease I will thaks soo mush cuz I really dont know how get the aplication work on the way I can see it.
If u seen the way to do it ease I will thaks soo mush cuz I really dont know how get the aplication work on the way I can see it.
#9
Re: question how can I join 2 tables or datagrids
Posted 05 October 2012 - 01:28 PM
Oh, I see. My eyes just glaze over when I see connection strings and data adapters. I didn't notice that you had OleDbDataAdapter's for two of them, and a SqlDbDataAdapter for the third.
It looks like you are taking the right approach there in your btnAceptar_Click() method.
I just don't quite understand your data. So each person has a unique ID, and this same ID is used to log him checking in and checking out. What happens when he checks in, then checks out, and then later checks in once more, and checks out again? Is he supposed to have only one row or two rows in the resultant grid to be displayed to the user?
It looks like you are taking the right approach there in your btnAceptar_Click() method.
I just don't quite understand your data. So each person has a unique ID, and this same ID is used to log him checking in and checking out. What happens when he checks in, then checks out, and then later checks in once more, and checks out again? Is he supposed to have only one row or two rows in the resultant grid to be displayed to the user?
#10
Re: question how can I join 2 tables or datagrids
Posted 05 October 2012 - 01:44 PM
they select on the clock the checkin and if they gone checkout they select out on the biometric clock the out option and checkout.
On the datadrid will show one row for in and one row for out but need validate the date for make the calculatioin of the hours, if some one mark more than one time it will depends if they mark in and out or just ins that other validations, but the principal problen for me is the combination of the rows, cuz Im new os C# dont know mush about the syntaxis and metods.
On the datadrid will show one row for in and one row for out but need validate the date for make the calculatioin of the hours, if some one mark more than one time it will depends if they mark in and out or just ins that other validations, but the principal problen for me is the combination of the rows, cuz Im new os C# dont know mush about the syntaxis and metods.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|