2010/03/17

C# week8_3


17/03/2010


 

Collection

  1. Arraylist
  2. Hashtable
  3. Stack
  4. Que

 

Arraylist & foreach

Arraylist al = new Arraylist();
al.Add( ab);
// class of object can be stored

 
string[] s = {"1", "2", "3"}
foreach(string k in s)
{
}
It will work.


 

ABC ab = new ABC();
Arraylist al = new Arraylist();
al.Add(1); //int
al.Add("2"); //string
al.Add(ab); //object of the class
foreach can't use, because datatype of this array is different.


 

IEnumerator

Arraylist al = new Arraylist();
al.Add(5);
al.Add("123");
al.Add(ab);

 
int k = (int)5;
string k1 = (string)123;
ABC k2 = (ABC)ab;
//object o = ab;
//object o1 =new ABC();
//Parent can refer child

 
casting
A a = new B();
B b = (B)a;

 
IEnumerator ie = new IEnumerator();

 
while(ie.Movenext())
{ ---------------- 2roles
1. True or Flase?
2. i++

 
ie.current.Tostring();
}

 
ADO.NET

  1. Data provider


  2. ADO.NET OBJECT
    1. SQL connection
    2. SQL command
    3. SQL data reader
    4. SQL data adaptor


Pros.



  • We can use any data source, either file, access, excel or data base.




  1. SQL connection
    SqlConnection conn = new SqlConnection
    (
    "Data source = path;
    Initial catalogue = data base name;
    Integrated security = SSPI"
    );



  2. SQL command
    SqlCommand cmd = new SqlCommand(" ", con);



  3. SQL datareader
    SqlDataReader rdr = cmd.Executereader.

    while(rdr.Read()) //true or false, read row 1
    {
    int id = rdr["ID"];
    string name = rdr["name"];
    Conseole.WriteLine(id+name);
    }

    rdr.Close();
    cmd.Close();

    cmd.ExcecuteNonQuery();//rdr don't use
    int i = (int)cmd.ExcecuteScaler();//How many rows?

0 件のコメント:

コメントを投稿

UA-9417263-1