ASP+資料庫操作例子

來源:互聯網
上載者:User
asp+|資料|資料庫 <%@ Page Language="VB"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ADO" %>

<script language="VB" runat="server">
Sub Page_Load(Src as object, E as EventArgs)
If rblLTorGT.SelectedIndex = -1 Then rblLTorGT.SelectedIndex = 0
End Sub

Sub btnRunQuery_OnClick(Sender As Object, E As EventArgs)
Dim objConnection As ADOConnection
Dim objDSCommand As ADODataSetCommand
Dim objDataSet As DataSet
Dim strSQLQuery As String

strSQLQuery = "SELECT * FROM sample " & _
"WHERE (Sales " & rblLTorGT.SelectedItem.Value.ToString() & " " &
txtSalesAmount.Text.ToString() & ") " & _
"ORDER BY " & ddlSortBy.SelectedItem.Value.ToString() &
ddlSortOrder.SelectedItem.Value.ToString()

objConnection = New ADOConnection("DBQ=" & Server.MapPath("database.mdb") & ";Driver=
{Microsoft Access Driver (*.mdb)};")

objDSCommand = New ADODataSetCommand(strSQLQuery, objConnection)

objDataSet = New DataSet()
objDSCommand.FillDataSet(objDataSet, "sample")

lblSQLCommandLabel.Text = strSQLQuery

EmployeeDataGrid.DataSource = objDataSet.Tables("sample").DefaultView
EmployeeDataGrid.DataBind()
End Sub
</script>

<html>
<body>

<form action="database.aspx" method="post" runat="server">
<strong>Sales:</strong><br />

<table border="0">
<tr><td>
<asp:RadioButtonList id="rblLTorGT" runat="server">
<asp:ListItem value="<" runat="server">Less Than</asp:ListItem>
<asp:ListItem value=">" runat="server">Greater
Than</asp:ListItem>
</asp:RadioButtonList>
</td><td>
<asp:TextBox id="txtSalesAmount" runat="server" />
<asp:RequiredFieldValidator runat="server"
id="validSalesEntry" controlToValidate="txtSalesAmount"
errorMessage="You must enter a sales amount!"
display="dynamic"
/>
<asp:RangeValidator runat="server"
id="validSalesAmount" controlToValidate="txtSalesAmount"
type="Integer" minimumValue="-32000" maximumValue="+32000"
errorMessage="You must enter an integer!"
display="dynamic"
/>
</td></tr>
</table>

<strong>Sort By:</strong><br />

<asp:DropDownList id="ddlSortBy" runat="server">
<asp:ListItem value="id" >Id</asp:ListItem>
<asp:ListItem value="last_name" >Last Name</asp:ListItem>
<asp:ListItem value="first_name" >First Name</asp:ListItem>
<asp:ListItem value="sales">Sales</asp:ListItem>
</asp:DropDownList>

<asp:DropDownList id="ddlSortOrder" runat="server">
<asp:ListItem value=" ASC" >Ascending</asp:ListItem>
<asp:ListItem value=" DESC">Descending</asp:ListItem>
</asp:DropDownList>

<asp:Button type="submit" id="btnRunQuery" text="Run Query" OnClick="btnRunQuery_OnClick"
runat="server" />
</form>

<p>
<strong>Results of:</strong> <asp:label id="lblSQLCommandLabel" runat="server" />
</p>

<asp:DataGrid id="EmployeeDataGrid" HeaderStyle-Font-Bold="True" ToolTip="This is Cool!" runat="server"
maintainviewstate="false" />

</body>
</html>



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.