Asp. NET tip: Analysis of stored procedures

Source: Internet
Author: User
asp.net| Stored Procedures | Tips 1//Analysis of stored procedures: examples
2//String g_name, string G_password for parameters passed to this stored procedure, string loging represents method name and type
3
4 public string Login (string g_name, String G_passord)
5 {
6
7 SqlConnection Conn = new SqlConnection (configurationsettings.appesettings["ConnectionString"]);
8//This is the connection statement
9/**//*
configurationsettings.appesettings["ConnectionString"]
11 indicates that a connection statement was loaded from configurantion
The statement in config is
<appSettings>
<add key= "ConnectionString" value= "SERVER=LOCALHOST;UID=SA;PWD=SA; database= Global "/>
</appSettings>
<system.web>
17 Note that the mark is placed above the <system.web>
18 */
SqlCommand Comm = new SqlCommand ("Login", Conn);
20//Create a new instance of SqlCommand Comm and mark it as a savings process named login.
21st
Comm.commandtype = CommandType.StoredProcedure;
23//Mark the Comm as the saving process
24
25
26
27//Below add parameters to stored procedure
SqlParameter parameterg_name = new SqlParameter ("@G_name", SqlDbType.NVarChar, 20);
29//New SqlParameter Savings Process parameter instance: instance named Pranmeterg_name
30//and defines a parameter name named "@G_name", which defines the type SqlDbType as nvarchar byte number 20;
31
Parameterg_name. Value = G_name;
33//For parameter instance Parameterg_name value is the value passed in from method login
34//Pay attention to parameterg_name. Value=g_name G_name and statement new SqlParameter ("@G_name", sqldbtype.nvarchar,20);
The @g_name in 35//is different, @G_name is a parameter name defined for a SqlParameter savings process
36
Panax Notoginseng Comm.Parameters.Add (prarameterg_name);
38//For comm Add parameter Paratemterg_name
39
40
41
42
SqlParameter Parameterg_password = new SqlParameter ("@G_password", SqlDbType.NVarChar, 20);
Parameterg_password. Value = G_password;
COMM.PARAMETERS.ADD (Parameterg_password);
46
SqlParameter parameterg_id = new SqlParameter ("@G_Id", SqlDbType.Int, 4);
Parameterg_id.direction = ParameterDirection.Output;
AN//parameterg_id.ddirection Gets or sets a value indicating whether the parameter can be
50//Can only input, can only output, bidirectional or stored procedure return value parameters
I//parameterdirection.output; This parameter is defined as an output parameter
COMM.PARAMETERS.ADD (paramerg_id);
53
54//Open the connection and execute command commands
Conn.Open ();
Comm.executenonquery ();
Conn.close ();
58
59//To get the value of parameterg_id.value processing
int g_id = (int) (parameterg_id.value);
61
if (g_id = 0)
63 {
return null;
65//Return NULL
66}
Or else
68 {
g_id. ToString ();
70//The performance situation of converting this information to an equivalent string
71}

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.