Executes a simple select query in asp+ and returns the data table to the DataGrid source program

Source: Internet
Author: User
Asp+|datagrid|select| Program | data | Execute------------------C # source program----------------
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.SQL"%>

<script language= "C #" runat= "Server" >

protected void Page_Load (Object Src, EventArgs E)
{
SqlConnection myconnection = new SqlConnection ("server=localhost;uid=sa;pwd=;d atabase=pubs");
Sqldatasetcommand mycommand = new Sqldatasetcommand ("SELECT * from Authors", MyConnection);

DataSet ds = new DataSet ();
Mycommand.filldataset (ds, "Authors");

Mydatagrid.datasource=ds. tables["Authors"]. DefaultView;
Mydatagrid.databind ();
}

</script>

<body>


<asp:datagrid id= "Mydatagrid" runat= "Server"
Width= "700"
Backcolor= "#ccccff"
Bordercolor= "BLACK"
Showfooter= "false"
Cellpadding=3
cellspacing= "0"
Font-name= "Verdana"
Font-size= "8pt"
Headerstyle-backcolor= "#aaaadd"
Maintainstate= "false"
/>

</body>

------------#VB源程序---------------
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.SQL"%>

<script language= "VB" runat= "Server" >

Sub Page_Load (Src as Object, E as EventArgs)

Dim DS as DataSet
Dim MyConnection as SqlConnection
Dim MyCommand as Sqldatasetcommand

MyConnection = New SqlConnection ("server=localhost;uid=sa;pwd=;d atabase=pubs")
mycommand = New Sqldatasetcommand ("SELECT * from Authors", MyConnection)

DS = new DataSet ()
Mycommand.filldataset (ds, "Authors")

Mydatagrid.datasource=ds. Tables ("Authors"). DefaultView
Mydatagrid.databind ()
End Sub

</script>

<body>


<asp:datagrid id= "Mydatagrid" runat= "Server"
Width= "700"
Backcolor= "#ccccff"
Bordercolor= "BLACK"
Showfooter= "false"
Cellpadding=3
cellspacing= "0"
Font-name= "Verdana"
Font-size= "8pt"
Headerstyle-backcolor= "#aaaadd"
Maintainstate= "false"
/>

</body>



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.