In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "ADO. NET sql server stored procedures how to call", in daily operation, I believe many people in ADO. NET sql server stored procedures how to call the problem there are doubts, small series access to various types of information, sorting out simple and easy to use operation methods, hope to answer "ADO. NET sql server stored procedures how to call" doubts helpful! Next, please follow the small series to learn together!
Here we mainly introduce ADO. NET, including ADO. NET sql server stored procedures and other aspects. The Disconnected class provides the basic structure for the ADO. NET Framework. An example of this class is the DataTable class, whose objects can store data without relying on a data provider. The Shared class constitutes the base class for data providers and is shared by all data providers. The DataProviders class can handle different types of data sources, and they are used to perform all data management operations on a particular database. For example, the SqlClient data provider can only work with SQL Server databases.
Database providers contain Connection, Command, DataAdapter, and DataReader objects. In normal ADO. NET programming, you first create a Connection object and give it the information it needs, such as a connection string. Then create a Command object that gives it the details of the SQL command to execute. This command can be a built-in SQL text command, stored procedure, or direct access to a table. You can also provide parameters for these commands if desired.
After you create the Connection and Command objects, you must determine whether the command returns a result set. If the command does not return a result set, you can execute the command by calling one of several Execute methods. On the other hand, if the command returns a result set, you must determine whether you want to keep the result set for future use without maintaining a connection to the database. If you want to preserve the result set, you must create a DataAdapter object and populate the DataSet or DataTable object with it. These objects can maintain information in disconnected mode. However, if you don't want to preserve the result set, but simply want to execute commands in a quick way, you can create DataReader objects using Command objects. The DataReader object requires a real-time connection to the database and is a forward-only read-only cursor.
Create a stored procedure in ADO. NET sql server as follows
CREATEPROCEDURE[dbo]. [UserProcedureWithParameter] @usernamenvarchar(50) AS select*from[user]whereusernamelike@username GO
In ADO. NET SQL Server, this is called
privatevoidPage_Load(objectsender,System.EventArgse)
{
SqlConnectioncon=newSqlConnection();
con.ConnectionString="workstationid=OVERMIND;packetsize=4096;userid=sa;password=sa;datasource=OVERMIND;
persistsecurityinfo=False;initialcatalog=wztj";
con.Open();
SqlCommandcm=newSqlCommand("UserProcedureWithParameter",con);
cm.CommandType=CommandType.StoredProcedure;
SqlParameterparameter1=newSqlParameter("@username",SqlDbType.NVarChar,50);
parameter1.Value="%"+"aa"+"%";
cm.Parameters.Add(parameter1);
DataSetds=newDataSet();
SqlDataAdapterad=newSqlDataAdapter(cm);
ad.Fill(ds,"user");
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
//Putusercodetoinitializethepagehere
}
At this point, on the "ADO. NET sql server stored procedures how to call" the study is over, I hope to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.