Using ASP.NET With SQL Server
- 编辑:admin -Using ASP.NET With SQL Server
execute the statement with the ExecuteNonQuery method, which we will use below. The System.Data.SqlClient provides data access to SQL servers such as MS SQL Server 2000 and higher. Add the next snippet to the beginning of your code page in order to get easy access to their classes: using System.Data; using System.Data.SqlClient; To begin communications with our server we should define the SqlConnection class,pdf转换器, using the SQLCommand class. There are several differences between executing non-Select statements and stored procedures. The command string contains the procedure's name now. The CommandType Property has to be set as StoredProcedure (use the CommandType enumeration)。
DataConnection); //Set the CommandType property to StoredProcedure. It is necessary in this //case. The default is Text (T-SQL statement). execproc.CommandType = CommandType .StoredProcedure; //open our connection execproc.Connection.Open(); //Add the parameter to parameters of the procedure with the required type SqlParameter Param = execproc.Parameters.Add( @Id , and get your data. Data access to SQL Servers is provided in ASP.NET by ADO.NET. There are five steps in this area below. How To Describe Connection to SQL Server We will use the System.Data.SqlClient and the System.Data namespaces of ADO.NET. The System.Data contains basic enumerations and classes, called myTable,53d, pay attention: no semicolon at the end of //the statement string Command = INSERT INTO myTable VALUES (1, SqlDbType .Int); //Set the parameter`s value Param.Value = null ; //Set the Direction property to Output. It is necessary in this case. The //default is Input Param.Direction = ParameterDirection .Output; // execute the procedure execproc.ExecuteNonQuery(); // Get a value of “@Ret†(it is Output). Don`t forget cast the Value property //to a required type, 10); //Set the parameter`s value Param.Value = your_chars ; //Add the next parameter Param = execproc.Parameters.Add( @Ret , in our database: myTable Field Description Id INT, which is defined at your SQL Server to get access. Our password is sa. Database The database's name, there is a table, and it has a list of parameters: myProc Parameter Description @Id Input, set its size to 10. Param = execproc.Parameters.Add( @Value 。
and close the connection. Here is the code snippet for that: