PDA

Επιστροφή στο Forum : ADO.NET στη c#



ring0
12-05-09, 22:23
καλησπερα παιδια,
ασχολουμαι με ado.net σε disconnected layer...
o ακολουθος κωδικας
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DB
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("***** Fun with DataSets *****\n");
// Create the DataSet object and add a few properties.
DataSet carsInventoryDS = new DataSet("Car Inventory");
carsInventoryDS.ExtendedProperties["TimeStamp"] = DateTime.Now;
carsInventoryDS.ExtendedProperties["DataSetID"] = Guid.NewGuid();
carsInventoryDS.ExtendedProperties["Company"] = "Intertech Training";
Console.ReadLine();
//...
// Create data columns
DataColumn carIDColumn = new DataColumn("CarID", typeof(int));
carIDColumn.Caption = "Car ID";
carIDColumn.ReadOnly = true;
carIDColumn.AllowDBNull = true;
carIDColumn.Unique = true;
DataColumn carMakeColumn = new DataColumn("Make", typeof(string));
DataColumn carColorColumn = new DataColumn("Color", typeof(string));
DataColumn carPetNameColumn = new DataColumn("PetName", typeof(string));
carPetNameColumn.Caption = "Pet Name";
Console.ReadLine();

// Now add DataColumns to a DataTable.
DataTable inventoryTable = new DataTable("Inventory");
inventoryTable.Columns.AddRange(new DataColumn[] { carIDColumn, carMakeColumn, carColorColumn, carPetNameColumn });

// Now add some rows to the Inventory Table.
DataRow carRow = inventoryTable.NewRow();
carRow["Make"] = "BMW";
carRow["Color"] = "Black";
carRow["PetName"] = "Hamlet";
inventoryTable.Rows.Add(carRow);
carRow = inventoryTable.NewRow();
// Column 0 is the autoincremented ID field,
// so start at 1.
carRow[1] = "Saab";
carRow[2] = "Red";
carRow[3] = "Sea Breeze";
inventoryTable.Rows.Add(carRow);
Console.ReadLine();
inventoryTable.PrimaryKey = new DataColumn[] { inventoryTable.Columns[0] };

carsInventoryDS.Tables.Add(inventoryTable);
// Now print the DataSet.
PrintDataSet(carsInventoryDS);
Console.ReadLine();
}
static void PrintDataSet(DataSet ds)
{
// Print out any name and extended properties.
Console.WriteLine("DataSet is named: {0}", ds.DataSetName);

Console.WriteLine();
foreach (DataTable dt in ds.Tables)
{
Console.WriteLine("=> {0} Table:", dt.TableName);
// Print out the column names.
for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
{
Console.Write(dt.Columns[curCol].ColumnName + "\t");
}
Console.WriteLine("\n----------------------------------");
// Print the DataTable.
for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
{
for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
{
Console.Write(dt.Rows[curRow][curCol].ToString() + "\t");
}
Console.WriteLine();
}
}
}
}
}

διαβαζοντας ειδα οτι οταν μιλαμε για disconnected layer oυσιαστικα δεν συνδεομαστε σε βαση δεδομενων...
αρα μπορει καποιος να μου πει γιατι ο πανω κωδικας εμφανιζει μονο
***** Fun with DataSets ***** και τιποτα απο τα υπολοιπα ...:hmm:

teacake
12-05-09, 22:36
Πάτησες καθόλου Enter, έτσι ώστε να ξεπεράσει τα Console.ReadLine();

Thuglife
12-05-09, 22:42
Το carIDColumn λες οτι είναι autoincrement στα comments αλλα δεν σετάρεις πουθενά το property.


carIDColumn.AutoIncrement = true;

Επίσης καλύτερα να χρησιμοποιήσεις Console.ReadKey(true) αντι για readline :)

ring0
13-05-09, 00:26
Το carIDColumn λες οτι είναι autoincrement στα comments αλλα δεν σετάρεις πουθενά το property.


carIDColumn.AutoIncrement = true;

Επίσης καλύτερα να χρησιμοποιήσεις Console.ReadKey(true) αντι για readline :)
ψαχνω κανα 2 μερες τι φταιει...:p :whistle:
thanks thug... τρεχει μια χαρα...:oneup:

@ ADSLgr.com All rights reserved.