In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to use the ASP.NET programming tool ASP.NET Web Matrix, aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
ASP.NET Web Matrix is an ASP.NET programming tool released by Microsoft, which has comprehensive functions and is light and flexible to use. Now let's take a look at how to use this tool to design web pages that combine data.
ASP.NET programming tool ASP.NET Web Matrix uses I. to establish a database.
ASP.NET Web Matrix now supports Microsoft's SQL Server, as well as its own simple desktop database, MSDE, which is similar to the personal version of SQL Server and can be downloaded for free. To illustrate the use of this database, we first go to the Microsoft website to download this free database tool.
Without the above database installed, the data panel of ASP.NET Web Matrix does not have a database (figure 1). In ASP.NET Web Matrix, when the user clicks the "Data" tab, ASP.NET Web Matrix will give a prompt to install the database.
At this point, we can install the SQL desktop database or download Microsoft's MSDE database for free. When the installation is complete, we can create data tables in this local database or on a remote SQL database server, and then perform specific operations on the data through ASP.NET.
After installing MSDE, click the "Data" panel of ASP.NET Web Matrix again to set up the database.
Because the database is set up and operated in the same way as using SQL Server security, we won't go into details here. Here, we set up a database called Orders.
After the above settings, ASP.NET Web Matrix can successfully operate the database, the following procedures we will operate on the above database, data tables. Users using SQL Server, install desktop SQL Server locally can directly connect to the remote database, general personal applications or learn to use, directly use Microsoft's MSDE can fully meet the requirements, after all, the price and management of SQL Serer are not easy for individual users to achieve.
ASP.NET programming tool ASP.NET Web Matrix II. Use ASP.NET to operate the database
After the establishment of the database, we can carry out database operations, the following we will be divided into several types of database operations, and strive to comprehensively introduce the essence of ASP.NET Web Matrix database operations.
1. Simple data release
We know that the simplest and most basic database operation is the release of data table information. Here, we first simply publish the Orders table information of the above Orders database to the web page through ASP.NET.
In ASP.NET Web Matrix, MXDataGrid server controls are specially used to display data tables from data sources such as databases. We can bind controls to data sources to display data when designing or running the program. Here, we use MXDataGrid server controls to display data.
(1) in ASP.NET Web Matrix, select "File"-> "New", and the "New File" dialog box appears
(2) in the dialog box that appears, select the "General" panel
(3) Select ASP.NET Page
(4) enter the newly created file path in the "Location" input box
(5) enter the newly created file name "myFirstDataGrid.aspx" in the "FileName" input box.
(6) Select "Visual Basic" as the ASP.NET development language in the "Language" drop-down box.
(7) Click the "OK" button
(8) in this way, the file "myFirstDataGrid.aspx" appears in the "Design" view of ASP.NET Web Matrix.
(9) Select the "Data" option page in the work window
(10) Click the database flag at the top of the options page, and the database selection interface appears, where we select the local "Orders" database.
(11) go back to the work window, select the "Orders" table, click the table with the left mouse button, and drag it to the ASP.NET page
(12) thus, in the design view, we will see the SQLDataSourceControl and MXDataGrid controls appear on the ASP.NET page
Here, we note a few points: first, ASP.NET Web Matrix will automatically set the properties of SQLDataSourceControl in the database specified by the tool; second, ASP.NET Web Matrix will automatically bind MXDataGrid and SQLDataSourceControl
(13) Save and run this file. The myFirstDataGrid.aspx we just designed will be automatically displayed in the browser. This page contains all the data of the Orders table. If the data in the database exceeds 10 rows, MxDataGrid will display 10 rows per page and automatically paginate the data. A link to the page will appear at the lower end of the page.
Through the above operations, the contents of the data table Ordrs will be automatically published through the web page, the above steps seem to be many, in fact, the specific design, it will be very simple. In this simple program, we do not need to write a single line of code to create an automatic paging data publishing page.
2. Format MXDataGrid
Above we used the default style of MxDataGrid to publish the data of the data table Orders, although this style is not bad, it is obvious that we can not only use this default setting to display the data for a long time, so in this section we will learn how to format MXDataGrid.
(1) Open the "myFirstDataGrid.aspx" we designed just now.
(2) Select MxDataGrid control
(3) Select the "AllowPaging" property in the "Properties" window
(4) set the "AllowPaging" property of MxDataGrid to "False", which will set whether MxDataGrid has data paging function. Here, we set it to "False".
(5) then select the "Fields" property in the "Properties" window
(6) the "Collection Editor" dialog box appears. Here, we will specifically set some properties about the display of MXDataGrid data fields.
(7) change the "OrderID" of the "HeaderText" attribute to "number"
(8) Click the "Ok" button to save and run this page
(9) through these settings, we can see that the original OrderID column header in MXDataGrid has been changed to "number".
3. Use Data Code Builder
Obviously, the database function we introduced above can only complete a small part of our actual development work. In order to design a more perfect database application, we need more powerful functions. Code Builder can meet this requirement. It is designed on the basis of code generator to help users design some common functional modules. ASP.NET Web Matrix itself already comes with some Code Builder, including some Code Builder specifically for database design. In the following articles, we will introduce the use of Select Code Builder to design a simple search database function. Now let's implement this function step by step.
(1) create a new ASP.NET page with a language choice of VB and a file name of myFirstDataPage.aspx
(2) in design view, select a "TextBox", a "DataGrid" and a "Button" control from the "Web Control" option page to the design page. Note here that we choose the "DataGrid" control, not the "MXDatGrid" control.
(3) the above is the design of the "Design" design view. Now, we click the "Code" tab to select the code view.
(4) on the left side of the code view, we can see the "Toolbox" column, where there is a Code Builder tab, in the Code Builder tab, we select "Select" to drag to the design area; we can see that there is not only an option "Select" here, but also other "Insert", "Delete" and so on, that is to say, basically common database operations can be completed through the methods introduced here.
(5) at this point, we see that the "Connect Database" dialog box appears, and here we select the "Orders" database in the "LocalHost" server.
(6) at this time, there is a Code Builder wizard named "Construct Select Query" (create database selection) ("Code Builder Wizard").
(7) in the "Tables" on the left side of the above interface, select the data table we need to query. Here, we select the "Orders" data table; on the right, "Columns" can select the data columns to be queried, ticking in front of the data columns to be queried. If you need to query all the data columns, you can select "*" or click the button "Slect All". Here, we select "*". At this time, we can see that part of the "Select" statement "SELECT [Orders]. * FROM [Orders]" has appeared in the "Preview" section of the above interface. We can see that it is a standard Select query statement.
(8) Click the "Where" button in the above interface, and the "Where Clause Builder" interface for setting the "Where" statement appears. This interface is divided into two parts: the left side is the left side where the Where statement is equal to the sign, and the right side is the right side where the Where statement is equal to the sign. In the "Columns" column on the left, we select "OrderID". In the "Filter" filter input box on the right, we enter "@ OrderID". This setting means to query all data records where "OrderID" equals the variable "OrderID". Click the "OK" button to return to the previous interface. We can see that the select statement has been changed to: SELECT [Orders]. * FROM [Orders] WHERE ([Orders]. [OrderID] = @ OrderID)
(9) in the interface "Construct Select Query", select the button "Next" to enter the next Code Builder Wizard, which is the "Preview" of the query statement.
(10) Click the "Text Query" button on the "Query Preview" interface to detect the previously designed query statement, and a dialog box for setting the @ OrderID value appears, which we set to "1" here; this means to select the data row with OrderId of 1.
(11) Click the "OK" button in the above interface, and we can see the query results directly.
(12) above we have seen that the result of the test run of the query statement is accurate. Click the button "Next" further. The third step of Code Builder Wizard appears. Here, we need to set the name of the query function and the way the query is used. Here, we can choose both "DataSet" and "DataReader" to implement data query.
(13) in the above interface, we choose "DataSet" to query the data and click the button "Finish" to end the wizard. At this time, we can see that a function has been added to the "Code" view, which is the "MyQueryMethod" function we have just established through the wizard.
Function MyQueryMethod (ByVal orderID As Integer) As System.Data.DataSet Dim connectionString As String = "server='localhost'; trusted_connection=true Database='Orders' "Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection (connectionString) Dim queryString As String =" SELECT [Orders]. * FROM [Orders] WHERE ([Orders]. [OrderID] = @ OrderID) "Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand (queryString, sqlConnection) sqlCommand.Parameters.Add (" @ OrderID ") System.Data.SqlDbType.Int) .Value = orderID Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter (sqlCommand) Dim dataSet As System.Data.DataSet = New System.Data.DataSet dataAdapter.Fill (dataSet) Return dataSet End Function
(14) Click the "Design" tab to return to the design view, double-click the "Button" button we added, and go to the "Code" code design window.
(15) add the following button event code to the code design view:
Sub Button1_Click (sender As Object, e As EventArgs) DataGrid1.DataSource = MyQueryMethod (CInt (TextBox1.Text)) DataGrid1.DataBind () End Sub the answer to the question on how to use the ASP.NET programming tool ASP.NET Web Matrix is shared here. I hope the above content can be of some help to everyone. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.