asp.net array application

Source: Internet
Author: User
Tags arrays sort access database

Response.Write (Array.indexof (ABC, "3", 1))//Look for "3" in the ABC array, starting from abc[1]

Response.Write (Array.lastindexof (ABC, "3"))//Look for "3" in the ABC array, starting from the last

-------------------------------------------------------------

String[] arrstr=new string[8]{"1", "4", "3", "2", "The" "," "," "," ","};//arrstr[0]= "1" ... arrstr[7]= "14"

Array.reverse (ARRSTR); Reverse Arrstr Array, at this time arrstr[0]= ... arrstr[7]= "1"

Array.Sort (ARRSTR); Sort the array, at which point the order is 1,12,14,14,16,2,3,4 (because it is sorted by string)

-------------------------------------------------------------

Array arrays to redefine size, must be in ReDim (VB), particularly slow for large arrays, and cannot be inserted in the middle; you cannot clear them (only set to null or 0)

ArrayList is slower to use than array, but does not need to redefine size, using Myarrlist.add ("Dog") s makes it easy to add data

ArrayList myarrlist = new ArrayList ();//Do not indicate the size of the array, and each element can be any data type;

Myarrlist.insert (1, "abc"); Insert element to array [1] Before

Myarrlist.removeat (1); Delete array elements [1]

Myarrlist.remove ("abc"); Delete an array element with the content "ABC", delete only once, and if you want to erase it all, you need to do a loop

-------------------------------------------------------------

ListItem newitem=new ListItem (); newitem.text= "a"; newitem.value= "B";

MYDROPDOWN.ITEMS.ADD (newitem);//Use ListItem to add items to the list box

-------------------------------------------------------------

Hashtable HT =new Hashtable (); ht["1"]= "a"; Ht. ADD ("2", "a");//hashtable usage

SortedList sl=new SortedList (); sl["1"]= "a"; ADD ("2", "a"),//sortedlist usage, automatically sorted according to key

foreach (DictionaryEntry ABC in SL)//Traversal SortedList approach

-------------------------------------------------------------

connstr=@ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\abc.mdb";//Connect to an Access database, note that the @ is added

Connstr= "Server=127.0.0.1;database=mydatabase;uid=username;pwd=password";//Connect SQL Server Database

Connstr= "Provider=SQLOLEDB.1; Server=127.0.0.1;database=mydatabase;initial Catalog=mycatalog;uid=username;pwd=password ";//OLE DB connection SQL Server database

-------------------------------------------------------------

connstr=@ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\abc.mdb";//Connect to an Access database, note that the @ is added

OleDbConnection con=new OleDbConnection (connstr); con. Open (); con. Close ();

Or

OleDbConnection con=new OleDbConnection ();

Con. Connectionstring=connstr;con. Open (); con. Close ();

-------------------------------------------------------------

OleDbConnection con=new OleDbConnection (CONNSTR);

OleDbCommand dc=new OleDbCommand ("SELECT * FROM Employees", con);

OleDbDataReader Dr=null;con. Open ();d R=DC. ExecuteReader ();

while (Dr. Read () ==true) Response.Write (dr["FirstName"]+ "
");

Dr. Close (); con. Close ();//datareader and connection to be closed, command not

There is no dr=null here. NET will be completed automatically, but plus dr=null will release the memory faster

-------------------------------------------------------------

And

The difference between:

1.txtASP uses onclick, while txthtml uses OnServerClick

2.txtASP uses text to set and get values, and txthtml uses Txthtml.value to set and get values

The 3. is written using the innertext attribute.

-------------------------------------------------------------

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.