asp+ Database Operations Example

Source: Internet
Author: User
Tags button type integer tostring
asp+| Data | database <%@ 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") & ";D river=
{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>

<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 a 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>



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.