Experience Sharing: ASP. NET database application analysis (1)

Source: Internet
Author: User
Tags microsoft frontpage

ASP. NET databases have many advantages in use, which have won wide favor from programmers. Now, let's take a look at the ASP. NET database application.

For a skilled ASP developer, the application of ASP. NET database is not only simple, but also powerful. Many Web developers chose ASP because of this. So far, they have always believed that ASP. NET database functions are good and can fully meet the development requirements.

I. NameSpace

To use the functions of the ASP. NET database, you cannot leave NameSpace. What is namespace? A little simpler. namespace is like a control in Delphi. You must put them in your Form to use them. Similarly, if you want to use ASP. NET database, you must first reference the corresponding namespace. The namespace of the ASP. NET database includes the following:

 
 
  1. <% @ Import NameSpace ="System. Data. SQL"%>
  2.  
  3. <Script Language ="VB"RunAt ="Server">
  4. Function createdatasource ()
  5. Dim conn AS SQLConnection
  6. Dim connstr As String
  7. Dim strsql AS String
  8. Dim sqlCmd AS SQLDataSetCommand
  9. Dim ds AS New DataSet
  10. 'Connect to the database
  11. Connstr =
  12. "Server = NHGA-D36KQ26TWB; DataBase = NorthWind; Pwd =; Uid = sa"
  13. Conn = New SQLConnection (connstr)
  14. 'SQL statement
  15. Strsql ="Select * from Products"
  16. 'Create DataSet
  17. SqlCmd = New SQLDataSetCommand (strsql, conn)
  18. 'Add table Products to DataSet
  19. SqlCmd. FillDataset (ds,"Products")
  20.  
  21. ReturnDs. Tables ("Products"). DefaultView
  22. End Function
  23.  
  24. 'Bind a data Function
  25. Sub BindGrid ()
  26. DataGrid1.DataSource = CreateDataSource ()
  27. DataGrid1.DataBind ()
  28. End Sub
  29.  
  30. 'Page Logon
  31. Sub Page_Load (Source AS Object, e as EventArgs)
  32. CreatedataSource ()
  33. BindGrid ()
  34. End Sub
  35. </Script>
  36.  
  37. <Html>
  38.  
  39. <Head>
  40. <Meta http-equiv ="Content-Language"Content ="Zh-cn">
  41. <Meta http-equiv ="Content-Type"Content ="Text/html; charset = gb2312">
  42. <Meta name ="GENERATOR"Content ="Microsoft FrontPage 4.0">
  43. <Meta name ="ProgId"Content ="FrontPage. Editor. Document">
  44. <Title> ASP. NET database usage </title>
  45. </Head>
  46.  
  47. <Body>
  48. <Form RunAt ="Server">
  49. <ASP: DataGrid id ="Maid"RunAt ="Server"/>
  50. </Form>
  51. </Body>
  52.  
  53. </Html>

The preceding is the simplest ASP. NET database application. The unique function is to list all records in the Products table of the NorthWind database. We can compare it with ASP and find that this program is so simple. To better understand the basic framework of the database application, let's take a look at how this database application is implemented.

When logging on to the page, call the CreateDataSource and BindGrid functions. The CreateDataSource function connects to the database and establishes DataView. The BindGrid function binds the data to the DataGrid. The specific statements of these two functions are described in the Code.


Related Article

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.