Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the SqlCommand.Prepare method

Shulou Source: shulou.com Published: 2022-06-03 11:02:18 11月15日 Update

This article mainly introduces how to use the SqlCommand.Prepare method, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

First of all, you need to reference the sqlclient; add {/ / to the program header file and add the parameters to the parameter collection of SqlCommand one by one through the PrePareCommand method.

Use of the SqlCommand.Prepare method

Use this method to improve execution efficiency for repeating statements to be executed. When using this method, you must name the three parameters of Parameters, otherwise an exception will be generated.

Preparecommand code

Privatevoidbutton1_Click (objectsender,EventArgse)

{

Stopwatchsw=newStopwatch ()

Sw.Start ()

Using (SqlConnectioncon=getCon ())

{

Con.Open ()

SqlCommandcom=newSqlCommand (null,con)

Com.CommandText= "INSERTINTOtb_user ([Username], [Password]) VALUES (@ UserName,@PassWord)"

Com.Parameters.Add (@ UserName, SqlDbType.NChar,20)

Com.Parameters.Add (@ Password, SqlDbType.NChar,20)

Com.Prepare ()

For (inti=0;i

Tags: Methods articles parameters average results three code value interest at the same time fame efficiency files time more friends computer knowledge programs tape Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Technology macOS MySQL Xiaomi