[Translation] Quick implementation of data sheet orders

xiaoxiao2021-03-06  15

Original source: http://www.codeproject.com/aspnet/aspnetdataFormNavigator.ASP Data Sheet Wide Pavilion Quick Implementation

Author: Mahmoud Nasr ASP.NET Data Form Wizard is similar to Windows applications.

Introduction

Since VS.NET provides a powerful data sheet warfare tool for the Windows form, I have been thinking why it doesn't provide similar tools for ASP.NET?

Because the Windows application and the ASP.NET application use the same ADO.NET class, it is possible to write such a tool in ASP.NET.

The first important thing we have cared is that it can use DataSet in a Windows application, and it is not the case in a web application. The best solution is to use DataReader because it can only read forward, so it will be a fatigue.

Two years ago, I have already started writing such a control. This is really a big job, but I think the result it brings will be beautiful.

background

But in the 2 month (2002) of our work, Stephen Walther "Unleashed ASP.NET" is published. In this book, I found that the author also wrote an identical control, but it is much more powerful than I wrote. It has many advantages, even better customization than the Data forms of the Windows application. It uses DataReader instead of DataSet, so it is a lightweight tool.

I don't want to go to discuss this control. Because Microsoft will make the same or better tools in the new VS.NET (Whidbey). But after I saw the new feature of Asp.Net 2.0 (ie whidbey), I was disappointed because Microsoft did not do such a tool as I expected. So I see that I am still useful.

This control itself is a collection of controls that inherited from the System.Web.ui.WebControls class, which can be divided into two points:

1. Treat a collection of controls for SQL Server.

2. Handling a collection of OLEDB controls for any database engine.

I have tested the SQL module, some bugs can be overcome. It is great. However, the OLEDB module is not smooth, I have tried in Oracle 9i, unfortunately it doesn't work properly because there is a bug when you accept the connection string. (I hope to repair it as soon as possible)

Use code

I have written an example, which demonstrates how to use this control, how to fully overcome some of its bugs.

1. Open vs.net, create a new project, select ASP.NET Web Applications.

2. Click Right-click in the Toolbox, select Add / Transfer (Subscription ", go to the bin directory under the downloaded project folder, then select SUPEREXPERT.DATAFORM.DLL, which will add DataForm's two controls to the Toolbox in. As you can see, the OLEDB control is green and the SQL control is red.

3. Put the SQLDATAPANEL control on the page and put all the controls you want (see you see as before).

4. Set the properties of the SqlDataPanel, make it point to the requested table, other critical areas are shown below:

skill:

Do not set up the connection string in the design mode. I have done this but it can't work, so it is best to set it when the page is loaded. (My connection string is stored in web.config and pointing to Northwind database in SQL Server) SqlDataPanel1.connection = New_

SqlConnection (System.Configuration._

ConfigurationSettings.AppSettings ("Connstr"))

5. Put the SQLDATANAVIGATOR control (which contains 4 wizard buttons), then connect it to the SqlDataPanel control, the code is as follows:

Sqldatanavigator1.controltonavigate = me.sqldataPanel1

Similarly, you should link the same string with the wizard, the code is as follows:

SqlDataNavigator1.connection = me.sqldataPanel1.connection

6. Put all the controls you want to use in this form, pay attention to, you must be the controls in the controls to be listed. For example, if you want to display data in the TextBox control, you must choose the DataTextBox control and put it on your SqlDataPanel control.

7. Two attributes in each data control are set:

DataField: Save the name of the binding area DataType: Save the data type of the binding area

8. Run this program, you will see that you can browse the data in the Employees table in the Northwind database smoothly and quickly.

prompt:

If you are downloading this control from Stephen's website, you will see an evaluation information, and the control you add here will not have evaluation information.

9. Stephen's control has several buttons "Add Record", "Update", and "Delete", but I have discovered that they don't work, so you must manually operate them like processing the regular buttons, this example will be like this:

This is all source code of this example [VB.NET]:

Private sub page_load (byval sender as system.Object, _

BYVAL E as system.eventargs) Handles mybase.load

'Put User Code to Initialize The Page Here

'Passing The Data Panel to The Navigator Coz it'll Not

'Work from Design Mode Properties (BUG)

Sqldatanavigator1.controltonavigate = me.sqldataPanel1

'Also Passing The Connection String from Web.config

'Becoz Passing it from the design mode will not work (bug)

SqldataPanel1.connection = new _

SqlConnection (System.configuration.configurationSettings.Appsettings (_

"ConnStr"))

'and finally passing it to the navigator Too.sqldatanavigator1.connection = me.sqldataPanel1.connection

End Sub

'Handling The Add Record BTN

Private sub DataAddButton1_click (Byval Sender as system.Object, _

Byval e as system.eventargs) Handles DataAddbutton1.click

DIM INSERTSTR AS STRING = "INSERT INTO Employees" & _

(Lastname, Firstname, Title, City, Country, Homephone, Notes) VALUES ('"

Me.la.lastname_txt.text "','" me.firstname_txt.text _ _ _ _

"','" Me.title_txt.text "','" me.city_txt.text _ _ _ _ _

"','" Me.cntry_txt.text "','" me.homePhone_txt.text _ _ _ _ _

"','" Me.notes_txt.text "") "

DIM CONN AS New_

SqlConnection (System.configuration.configurationSettings.Appsettings (_

"ConnStr"))

DIM CMD AS New Sqlcommand (InsertStr, Conn)

Try

Conn.open ()

cmd.executenonquery ()

Finally

CONN.CLOSE ()

END TRY

End Sub

'Handling the Delete BTN

Private sub delete_btn_click (byval sender as system.object, _

Byval e as system.eventargs Handles Delete_btn.click

DIM DELSTR AS STRING = _

"Delete from Employees Where Employeeid = '" _ _ _

Me.empid_txt.text "'"

DIM CONN AS New_

SqlConnection (System.configuration.configurationSettings.Appsettings (_

"ConnStr"))

DIM CMD AS New Sqlcommand (DELSTR, CONN)

Try

Conn.open ()

cmd.executenonquery ()

Finally

CONN.CLOSE ()

END TRY

End Sub

'HANDLING THE UPDATE BTN

Private sub DataUpdateButton1_click (Byval Sender as system.Object, _

Byval e as system.eventargs) Handles DataUpdateButton1.click

DIM UpdateStr As String = "Update Employees Set Lastname = '" _Me.lastname_txt.text ", firstname ='" _ _

Me.Firstname_txt.text "', title ='" _ _ _

Me.title_txt.text "', city ='" _

Me.city_txt.text "', country ='" _

Me.cntry_txt.text ", homephone = '" _ _ _

Me.HomePhone_txt.text "', notes ='" _ _ _ _ _

Me.notes_txt.text "'Where urgeyeeid ='" _ _

Me.empid_txt.text "'"

DIM CONN AS New_

SqlConnection (System.configuration.configurationSettings.Appsettings (_

"ConnStr"))

DIM CMD AS New Sqlcommand (UpdateStr, Conn)

Try

Conn.open ()

cmd.executenonquery ()

Finally

CONN.CLOSE ()

END TRY

End Sub

转载请注明原文地址:https://www.9cbs.com/read-47482.html

New Post(0)