26/01/2010, 09:07
|
| | Fecha de Ingreso: noviembre-2008 Ubicación: Uruguay
Mensajes: 49
Antigüedad: 16 años, 1 mes Puntos: 1 | |
Respuesta: concatenar datos de una tabla en un combobox en visual c# acá va una referencia a tener en cuenta...
Código:
SqlConnection conn;
SqlDataAdapter daCustomers;
SqlDataAdapter daOrders;
DataSet ds = new DataSet();
// Create a connection to the Pubs database
conn = new SqlConnection("data source=localhost; "integrated security=true;initial catalog=northwind");
// Create the first DataTable
daCustomers = new SqlDataAdapter ("select CustomerID, CompanyName from Customers", conn);
daCustomers.Fill(ds, "Customers");
'Create the second DataTable
daOrders = New SqlDataAdapter ("select CustomerID, OrderID, OrderDate, ShippedDate " &
"from Orders", conn)
daOrders.Fill(ds, "Orders")
// Create the second DataTable
daOrders = new SqlDataAdapter ("select CustomerID, OrderID, OrderDate, ShippedDate " +
"from Orders", conn);
daOrders.Fill(ds, "Orders");
// Create DataRelation: each publisher publishes many titles
DataRelation dr;
DataColumn parentCol;
DataColumn childCol;
parentCol = ds.Tables["Customers"].Columns["CustomerID"];
childCol = ds.Tables["Orders"].Columns["CustomerID"];
dr = new DataRelation("CustOrders", parentCol, childCol);
ds.Relations.Add(dr);
currentParentRow = ds.Tables["Customers"].Rows[dgCustomers.SelectedIndex];
foreach(DataRow r in currentParentRow.GetChildRows("CustOrders"))
{
Label1.Text += r["OrderID"] + ",";
}
|