• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

ASP+数据库操作例子

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 15次 | 进入软件测试论坛讨论

领测软件测试网 <%@ 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>

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网