In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "ADO.NET stored procedure call example analysis", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "ADO.NET stored procedure call example analysis" bar!
This example is simple because the stored procedure does not require any input parameters. In other words, you don't need any external information to find the ten most expensive products. The stored procedure can do this without outside help. However, most stored procedures require input parameters to perform their functions. In the next example, let's look at how to pass input parameters to the ADO.NET stored procedure. We will use CustomerID to get all orders from the relevant customers and use an ADO.NET stored procedure named CustOrderHist (which already exists in the Northwind database).
Create another button on the used form and place the following line of code after the button's Click event:
Dim sConnectionString As String = _ "server=localhost;uid=sa;pwd= Database=Northwind "Dim cnNorthwind As New SqlConnection (sConnectionString) Dim cmdOrders As New SqlCommand (" CustOrderHist ", cnNorthwind) cmdOrders.CommandType = CommandType.StoredProcedure 'sets the parameter Dim prmCustomerID As New SqlParameter () prmCustomerID.ParameterName =" @ CustomerID "prmCustomerID.SqlDbType = SqlDbType.VarChar prmCustomerID.Size = 5 prmCustomerID.Value =" ALFKI "cmdOrders.Parameters.Add (prmCustomerID) Dim daGetOrders As New SqlDataAdapter (cmdOrders) Dim dsOrders As New DataSet () daGetOrders.Fill (dsOrders," Orders ") DataGrid1.DataSource = dsOrders.Tables (" Orders ")
This code is very similar to the code in the previous example, except that after you create the Command object, you configure it with a Parameter object and add it to the parameter collection of Command. In this example (closer to the demo software), the customer ID is hard-coded, and the Value property of the parameter is usually set to some user input data. However, other properties of the parameter can be set exactly as in this example. All parameter settings in this example are explicit. Some developers like this style because it is easy to explain. However, some developers prefer to use equivalent methods with fewer lines of code:
Dim sConnectionString As String = _ "server=localhost;uid=sa;pwd=;database=Northwind" Dim cnNorthwind As New SqlConnection (sConnectionString) Dim cmdOrders As New SqlCommand ("CustOrderHist", cnNorthwind) cmdOrders.CommandType = CommandType.StoredProcedure cmdOrders.Parameters.Add (New _ SqlParameter ("@ CustomerID", SqlDbType.VarChar, 5) cmdOrders.Parameters ("@ CustomerID"). Value = "ALFKI" Dim daGetOrders As New SqlDataAdapter (cmdOrders) Dim dsOrders As New DataSet () daGetOrders.Fill (dsOrders, "Orders") DataGrid1.DataSource = dsOrders.Tables ("Orders")
This code has exactly the same effect as the previous example. But each parameter requires only two lines of code instead of six. If the stored procedure contains a large number of parameters (as shown in some later examples), there will be a significant difference in the number of lines of code required, so we will use this form later.
Thank you for your reading, the above is the content of "ADO.NET stored procedure call example Analysis". After the study of this article, I believe you have a deeper understanding of the problem of ADO.NET stored procedure call example analysis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.