The relationship between the structure definition of the dataset and the instance (turn)

Source: Internet
Author: User
Tags definition
The relationship between the structure definition of data dataset and the instance
Www.yescnet.com CNET Chinese web

In. NET database development, it is unavoidable to use Datasets (datasets), when reading the MSDN Learning DataSet, because there is no clear distinction between the definition and the instance of the dataset, in the operation, there is always a dataset, where a dataset, around, but do not know why, When all is done, think carefully before discovering that this dataset is not a dataset, part of the dataset definition, and the other part is a dataset instance full of data. Therefore, for the convenience of everyone's understanding, here will be the definition of data sets and examples of the analysis, with a view to help you on the audience of. NET multi-tier database development. The example program in this article is walkthrough in MSDN in Vs.net Studio Beta 2 (Don't tell me you can't find it): The VB class in WebForms application Walkthroughs. If you have nothing to read, you can refer to it.

Following the example program, the analysis shows the definitions and instances of these data sets that are easily confusing in different situations.
First, we create a new VB project. The project type is Visual Basic Projects, in the template selection asp.net Web, named MyWebForm.
After Visial Studio.NET has produced a lot of files for you, add a component to the project. Then add a SqlDataAdapter or Oledataadapter to the component and, depending on the wizard, connect to the database and configure the database adapter. The database adapter is directly facing the database, and all commands for the operation of the database such as SELECT, UPDATE, INSERT, delete, etc., are generally assigned to the adapter. When the adapter is configured, you will find the menu item with more data on the menu and click on it, and you will find the menu item "Generate DataSet". After clicking, pop up the data set of the window, you can choose to create a new dataset, the name of the dataset is dscustomers, at this time the dataset is actually refers to a dataset definition, that is, in XML format, file name is ' dscustomers.xsd ' DataSet definition file. Note that it does not contain any data in the database, but merely describes what the data in the future is meant to be when it is used to describe the data set (which contains the real data, which is the instance). Select the tables that you want to add to the dataset, and verify that the check boxes for the last ' Add this dataset to the designer ' are not ticked. The reason to remove the tick here is because it is the option to decide whether to set up a dataset instance on the designer, and to verify this, you can try to make a tick. If you use the default DataSet1 DataSet name, the effect is not obvious, because the dataset defines the file named ' DataSet1.xsd ', and the dataset instance added to the designer is named ' DataSet1 ', which is confusing, If you change the dataset name to ' Dsmydataset ' yourself, you will find that the generated dataset defines the file name ' Dsmydataset.xsd ', and the dataset instance that you add to the designer is called ' DsMyDataset1 ', it is obvious at this point that the dataset on the designer is a dataset instance that can hold the actual data. We do not need to extract the data from the designer, so do not tick it before this option. After the dataset is generated, I'd like to remind you that when you hit the open XSD file, the screen you see is quite different from the screenshot in MSDN. I've never been able to understand how the screenshot on MSDN was made, why it had two elements, and I always came up with an element in its way. Here, I wandered for a long time until I was sure I was right, and the rest didn't want to see if MSDN was wrong.
We need to add a method in this component that is specifically used to populate the incoming dataset instance. The code is like this:
Public Sub FillDataSet (ByVal dSet as Dscustomers)
SqlDataAdapter1.Fill (DSet)
End Sub
Save the component.
Next, we'll add a dataset instance to the interface. Click WebForm1.aspx, drag a dataset control from the data category in the toolbox, and pop the Add DataSet window. Select the first button and select the dataset definition dscustomers we just set up, OK. So WebForm1 's lower control box has a 1-end dataset dsCustomers1, note this 1, which indicates that this is a dataset instance defined using the previous dataset. At this point, it has no data, we double-click the WebForm1.aspx page, open the Code editing window. To fill the dataset instance with data, we can take advantage of the component created by the previous step. First declare Dim mycomp as Component1. Because component belongs to this project, so everything is normal, if component belongs to other projects or directly online, then you must first quote it. Next, we populate the dataset instance in WebForm1.aspx with the method in Componet. The code is:
Mycomp.filldataset (DsCustomer1). OK, because the incoming parameter of this method is defined by Dscustomer, and now the instance on the WebForm1.aspx is defined by Dscustomer, so dsCustomer1 can pass in component, Fill with the data adapter in component.
Through the above analysis, I believe you should no longer confuse the definition of the dataset with the actual dataset instance you are using.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.