0303 dbase in c sharp data table and data column data row class سى شارب و قواعد البيانات
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication22
{
class Program
{
static void Main(string[] args)
{
DataTable tblEmp = new DataTable("emp");
tblEmp.Columns.Add("empno", typeof(int));
tblEmp.Columns.Add("empname");
tblEmp.Columns.Add("address");
Console.WriteLine(tblEmp.Columns.Count);
Console.WriteLine(tblEmp.Rows.Count);
DataRow row1;
row1 = tblEmp.NewRow();
row1[tblEmp.Columns[0]] = 111;
row1[tblEmp.Columns[1]] = "Ahmed";
row1[tblEmp.Columns[2]] = "Cairo";
tblEmp.Rows.Add(row1);
Console.WriteLine(tblEmp.Rows.Count);
DataRow row2;
row2 = tblEmp.NewRow();
row2[0] = 222;
row2[1] = "Adel";
row2[2] = "Giza";
tblEmp.Rows.Add(row2);
Console.WriteLine(tblEmp.Rows.Count);
DataRow row3;
row3 = tblEmp.NewRow();
row3["empno"] = 333;
row3["empname"] = "Eslam";
row3["address"] = "Giza";
tblEmp.Rows.Add(row3);
Console.WriteLine(tblEmp.Rows.Count);
object[] row4 = { 444, "Amr", "Alex" };
tblEmp.Rows.Add(row4);
Console.WriteLine(tblEmp.Rows.Count);
tblEmp.Rows.Add(new object[] { 555, "Omar", "Alex" });
Console.WriteLine(tblEmp.Rows.Count);
DataRow row;
for (int x = 1; x <= 10; x += 1)
{
row = tblEmp.NewRow();
row[0] = x;
row[1] = "Name" + x;
row[2] = "Address " + x;
tblEmp.Rows.Add(row);
}
Console.WriteLine(tblEmp.Rows.Count);
for (int r = 0; r < tblEmp.Rows.Count; r += 1)
{
for (int c = 0; c < tblEmp.Columns.Count; c += 1)
{
Console.Write(tblEmp.Rows[r][c] + (c < tblEmp.Columns.Count - 1 ? "\t ;\t " : " "));
}
Console.WriteLine();
}
//1
//2
//3
//4
//5
//15
//111; Ahmed; Cairo
//222; Adel; Giza
//333; Eslam; Giza
//444; Amr; Alex
//555; Omar; Alex
//1; Name1; Address 1
//2; Name2; Address 2
//3; Name3; Address 3
//4; Name4; Address 4
//5; Name5; Address 5
//6; Name6; Address 6
//7; Name7; Address 7
//8; Name8; Address 8
//9; Name9; Address 9
//10; Name10; Address 10
//Press any key to continue . . .
}
}
}