17/03/2010
Collection
- Arraylist
- Hashtable
- Stack
- 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();
}
- Data provider
ADO.NET OBJECT
- SQL connection
- SQL command
- SQL data reader
- SQL data adaptor
- SQL connection
We can use any data source, either file, access, excel or data base.
SQL connection
SqlConnection conn = new SqlConnection
(
"Data source = path;
Initial catalogue = data base name;
Integrated security = SSPI"
);
SQL command
SqlCommand cmd = new SqlCommand(" ", con);
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 件のコメント:
コメントを投稿