Data | Database one. Database connection
The attached database information is available in the following file for easy unified management.
web.config//still don't understand this. Better learn, I think very useful,. NET is of course to use. NET things.
このセクションは, アプリケーションの 権 limit のポリシーを set します. この set により, ユーザーまたはロールによるアプリケーションリソースへのアクセスを can したり,
Refuse to したりできます. ワイルドカード: "*" は Full member を, "?" は Anonymous
(not recognized) ユーザーを table します.
-->
<authorization>
<allow users= "*"/> <!--* All ユーザーへの can-->
<!--<allow users= "[ユーザーのコンマ area I did easily a 覧]"
Roles= "[ロールのコンマ District I did easily one 覧]"/>
<deny users= "[ユーザーのコンマ District Cut I did easily one 覧]"
Roles= "[ロールのコンマ District I did easily one 覧]"/>
-->
</authorization>
<!--アプリケーションレベルのトレースログの setting
アプリケーションレベルのトレースは, アプリケーション the full ページのトレースログ output を demonstration にします.
アプリケーショントレースログを has demonstration にするには, trace enabled= "true" I set します. Pageoutput= "true" I set された field,
トレース sentiment report が each ページの under I said されます. それ outside the は,
Connection code:
Using System.Data.SqlClient;
The namespace required for using system.collections.specialized;//to manipulate XML
String strconn= (String) (NameValueCollection) context.getconfig ("System.web/database")) ["strconn"];
Operation Code:
1, through the database stored procedures to operate the database, through the middle layer to do the project is the most ideal. can improve security and overall performance.
using (SqlConnection conn = new SqlConnection (strconn))
{
SqlCommand cmd = new SqlCommand ("SP_SP", conn);
cmd.commandtype=commandtype.storedprocedure;//declaration is a call to a stored procedure
Cmd. parameters["@SNO"]. Value=sno. Text;
Cmd. parameters["@TD"]. Value=checkbase.text;
Cmd. parameters["@S_NOTE"]. value=snote.text;//to the parameter value
Conn. Open ();
if (cmd. ExecuteNonQuery ()!=0)//execution does not return a collection
okmsg.text= "Sdts Deng registration Complete";
Else
okmsg.text= "Sdts Deng Registration failure";
}
2, direct output SQL statement
String strsql= "UPDATE NWind.NUser.DATA SET sno= '" +sno. Text;//sql server needs to indicate the name of the database in which the table resides and the user name that created the table
if (checkbase.text!= "")
strsql+= "', MONTH = '" +checkbase.text+ "/01";
strsql+= "' WHERE SNO = '" +sno. text+ "'";
Conn. Open ();
SqlCommand cmd = new SqlCommand (strsql,conn);
if (cmd. ExecuteNonQuery ()!=0)
okmsg.text= "データが Deng registration しました";
Else
okmsg.text= "Sdts Deng Registration failure";
}
3. Retrieval syntax SqlDataAdapter is used in conjunction with datasets and is generally used for special operations on access to datasets
More commonly used
Private DataSet GetData ()
{
String strconn= (String) (NameValueCollection) context.getconfig ("System.web/database")) ["strconn"];
using (SqlConnection conn = new SqlConnection (strconn))
{
SqlCommand cmd = new SqlCommand ("Sp_co", conn);
Cmd.commandtype=commandtype.storedprocedure;
Cmd. Parameters.Add ("@place", sqldbtype.varchar,2);
Cmd. parameters["@place"]. Value=place.text;
Conn. Open ();
SqlDataAdapter da = new SqlDataAdapter ();
Da. Selectcommand=cmd;
DataSet ds=new DataSet ();
Da. Fill (ds, "VCO");
You can use a dataset like a local database, where you can store multiple datasheets and implement the functionality you want to achieve. Details such as table processing have column deletions increased, and multiple tables are processed. Wait a minute
count.text= "ヒット:" +ds. tables["VCO"]. Rows.Count.ToString () + "pieces";
return DS;
}
}
4, when only used to read the data recommended to use SqlDataReader, read faster than the above a lot faster
private void Dataloader ()
{
String strconn= (String) (NameValueCollection) context.getconfig ("System.web/database")) ["strconn"];
using (SqlConnection conn = new SqlConnection (strconn))
{
SqlCommand cmd = new SqlCommand ("Sp_list", conn);
Cmd.commandtype=commandtype.storedprocedure;
Cmd. Parameters.Add ("@no", sqldbtype.varchar,6);
Cmd. parameters["@no"]. Value=no. Text;
Conn. Open ();
using (SqlDataReader dr = cmd. ExecuteReader ())
{
if (Dr. Read ())
{
c.text=dr["C"]. ToString (); Get data from a column name
m.text=dr["MTC"]. ToString (); //
}
Else
Okmsg.text= "このデータがありません, and は 検 sent I did easily first of the は violation of law です. ";
}
}
}
Note that all of these are using a using (), and the advantage is that you do not need to connect the open database to the close () operation.
Because I have a very poor memory, so I like this method
Let's get here first. What the stored procedures in the database do specifically. Let's talk about it later.
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.