Asp Tutorials

Contact ASP.Net(6 intimately)

Name a space about Namespace() use

We see in the program in front,I am commonly used %26lt;% @ Import Namespace= %26quot;System.Data%26quot; %%26gt; , this is to citing the Namespace that M$ offers for us, this and ASP are different,The ability after the Namespace that we must cite to be concerned with our operation first in ASP.net uses corresponding function.Actually spoken parts in an opera,A Namespace; is a component.This is about the advanced application of ASP.net,I am met retrospective is paragraphic tell.(should write there nevertheless,Time. . . . . . ..

Below me simple enumeration a few commonly used Namespace

%26lt% @ Import Namespace= %26quot;System.Data%26quot; %%26gt; When processing data, use
%26lt;% @ Import Namespace= %26quot;System.Data.ADO%26quot; % %26gt; Use when use ADO.net;
%26lt;% @ Import Namespace= %26quot;System.Data.SQL%26quot; %%26gt; Database of SQL Server is special
%26lt;% @ Import Namespace= %26quot;System.Data.XML%26quot; %%26gt; Need not see processing XML be used
%Ǻlt;% @ Import Namespace= %26quot;System.IO%26quot; %%26gt; Use when transaction file
%26lt% @ Import Namespace= %26quot;System.Web.Util%26quot; %%26gt; The everybody when sending mail can be used
%26lt;% @ Import Namespace= %26quot;System.Text%26quot; %%26gt; When text codes, use

Those who handle database need east

Explained Namespace, we can discuss the application of the database formally.From above can see,We operate a database,We need to cite below two Namespace

%26lt;% @ Import Namespace= ຎquot;System.Data%26quot; %%26gt;
%26lt;% @ Import Namespace= %26quot;System.Data.SQL%26quot; %%26gt;

Actually System.Data.SQL can be replaced with System.Data.ADO,SQL is SQL Server special,ADO can support any databases (should exist on lead plane only corresponding drive went, be like Access, mysql, of Oracle and so on) , the database as a result of flying knife is SQL Server here, can use ADO originally,But think M$ comes out SQL independently alone,Why need not.Can bring how many profit as to it,Flying knife had not checked,It is a bit better to should compare ADO for certain to SQL Server.

No matter be ADO or SQL,They have a few main targets to be used at the operation

Connections Concatenate to a database,In order to facilitate the application from the back (the Connections in similar ADO)
Commands The place of executive SQL statement
DataReader Read take the data content that after carrying out, returns
DataSet Store data,The function is powerful,We will be specific explain
DataSetCommand Executive SQL statement, stock data DataSet

The may most fathomless inside this is DataSet, we are not in charge of him first,Take soft operation first

Connections(SQLConection or ADOConnection)

Its main task establishs a tie with database server namely

%26lt;% @ Page Language= %26quotC#%26quot; %%26gt;
%26lt;% @ Import Namespace= %26quot;System.Data%26quot; %%26gt;
%26lt;% @ Import Namespace= %26quot;System.Data.SQL%26quot; %%26gt;
%26lt;Script Language= ຎquot;C#%26quot; Runat= %26quot;Server %26quot;%26gt;
Public Void Page_Load(Object Src, eventArgs E)
{
StringstrProvider= “server=localhost;uid=sa;pwd=;database=aspcn” ;
SQLConnection MyConnection=new SQLConnection(strProvider);
}
%26lt;/script%26gt;

We established a tie that the name is MyConnection above,Was like us to open a tie with ADODB.Connection in ASP. This coupling we are in Command perhaps will be used in DataSetCommand.

Its a few useful attribute and method have

ConnectionString is obtained or set the sentence of concatenate database
What ConnectionTimeout is obtained or install concatenate database is the longest,Also be overtime time
DataBase is obtained or the setting wants the database name that open on database server
DataSource is obtained or install DSN, authority won’t be new:)
Password is obtained or install a password
UserID is obtained or the setting lands a name
State acquires the position that binds at present
Open() opens tie
Close() shuts coupling
Clone() clone binds.(breathe out ah,Sheep is OK Connection I am OK also)


The usage that we also see them through a trivial example:
SQLConnection MyConnection = New SQLConnection();
MyConnection.DataSource = “mySQLServer” ;
MyConnection.Password = “” ;
MyConnection.UserID = “sa” ;
MyConnection.ConnectionTimeout = 30;
MyConnection.Open();
MyConnection.Database = “northwind” ;
MyConnection.IsolationLevel = IsolationLevel.ReadCommitted

Commands(SQLCommand or ADOCommand)

We opened a tie in the program above,We use this here with respect to need, see example had compared:

%26lt;% @ Page Language= %26quot;C#%26quot; %%26gt;
%26lt;% @ Import Namespace= %26quot;System.Data%26quot; %%26gt;
%26lt;% @ Import Namespace= %26quot;System.Data.SQL%26quot; %%26gt;
%26lt;Script Language= %26quot;C#%26quot; Runat= %26quot;Server%26quot; %26gt;
Public Void Page_Load(Object Src, eventArgs E)
{
StringstrProvider= “server=localhostuid=sa;pwd=;database=aspcn” ;
String StrIndex= “select * From Aspcn Where Purview=’webmaster’” ;
SQLConnection MyConnection=new SQLConnection(strProvider);
SQLCommand MyCommand = New SQLCommand(strIndex, myConnection);
MyConnection.Open(); / / open tie
MyCommand.ExecuteNonQuery() / / executive SQL,But do not return any records
MyConnection.Close();
}
%26lt;/script%26gt;

Two parameter cited when we establish SQLCommand target in above example (StrIndex, myConnection) , from inside source program we also can see what StrIndex represents is executive SQL statement,MyConnection is the tie that we establish before. Next we are about to open MyConnnection first, carry out this SQL statement again next.We are carried out here those who use is ExecuteNonQuery() method,Do not return record volume so,Just return the record that suffers an effect several.

Such it is OK also to we are opened here and shut a database doing.

StringstrProvider= “server=localhost;uid=sa;pwd=;database=aspcn” ;
String StrIndex= “select * From Aspcn Where Purview=’webmaster’” ;
SQLConnection MyConnection=new SQLConnection(strProvider);
SQLCommand MyCommand = New SQLCommand(strIndex, myConnection);
MyCommand.ActiveConnection.Open();
MyCommand.ExecuteNonQuery();
MyCommand.ActiveConnection.Close();

Earnings result and foregoing same.Carry out statement of a SQL to have a lot of kinds of methods so.And still not merely two kinds,DataSetCommand learned at the back of us, law of that dozen of evolution is N planted:) this saw the demand of your habit and program with respect to need;)

We see the method with commonly used Command and property first

ActiveConnection is obtained or install coupling Connections
The SQL statement that CommandText carries out or store process (StoredProcedure) name
What CommandTimeout carries out is the longest
The type that CommandType Command operates (StoredProcedure, text, tableDirect) three kinds, acquiescent Text
Parameters operation stores use when the process
Execute() carries out SQL statement or store process
ExecuteNonQuery() is Alexandrine,Distinction depends on returning record volume
Command of Clone() clone


See a case likewise:


String MySelectQuery = “SELECT * FROM Categories ORDER BY CategoryID” ;
StringmyConnectString= “userid=sa;password=;database=northwind;server=mySQLServer” ;
SQLCommand MyCommand = New SQLCommand(mySelectQuery);
MyCommand.ActiveConnection = New SQLConnection(myConnectString);
MyCommand.CommandTimeout = 15;
MyCommand.CommandType = CommandType.Text;%26lt;/ FONT%26gt;





Handgrip hand teachs your use Java to write ASP package (4)

Two, compile project Project:

    is good,We should prepare to compile component of our Java COM eventually now.The Build/Build in clicking tool column,In the condition column below,You can see different condition message shows package is being registered and Type Library is being generated.After this,You can see Solution Update Succeeded of a successful information,Congratulation the first when you compiled you Java COM component that uses target of visit ASP interior.

Three, package is registered on long-range server

    compiles component of a COM when your use Visual Studio,Its can automatic enrollment package and generate Type Library,But if you want to use your component on other server,So the component that if you want to register you on other machine,your component registers before you are using it,You can use following form below DOS condition:

    C:\Regsvr32 WayneStudio.dll

Notice,Use the DLL file name after you are written and be being compiled to replace WayneStudio.dll.


  • Copyright © 1996-2010 Programming tutorials for beginners,. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress