Database query form Demo (VB.net) : Database Query « Components « ASP.Net






Database query form Demo (VB.net)

<%--
Code revised from 

ASP.NET Tips & Techniques (Paperback)
by Greg Buczek 


# Publisher: McGraw-Hill/Osborne Media; 1st edition (May 21, 2002)
# Language: English
# ISBN: 0072225149

--%>   
    <%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
    Dim DBConn as OleDbConnection
    Dim DBCommand As OleDbDataAdapter
    Dim DSPageData as New DataSet
    Dim TheQuery as String
    DBConn = New OleDbConnection( _
        "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
        & "DATA SOURCE=" _
        & Server.MapPath _
        ("EmpDB.mdb;"))
    TheQuery = "Select " & txtFieldList.Text _
        & " From " & txtTableName.Text
    If txtWhere.Text <> "" Then
        TheQuery = TheQuery & " Where " _
            & txtWhere.Text
    End If
    If txtOrder.Text <> "" Then
        TheQuery = TheQuery & " Order By " _
            & txtOrder.Text
    End If
    DBCommand = New OleDbDataAdapter(TheQuery, DBConn)
    DBCommand.Fill(DSPageData, _
        "QueryResults")
    dgQuery.DataSource = _
        DSPageData.Tables("QueryResults").DefaultView
    dgQuery.DataBind()
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Raw Query Page</TITLE>
</HEAD>
<Body LEFTMARGIN="40">
<form runat="server">
<BR><BR>
<asp:label 
    id="lblMessage2" 
    font-size="10pt"
    font-name="Lucida Console"
    text="Enter your query text"
    runat="server"
/>
<BR>
Select (Field List)
<BR>
<asp:textbox
    id="txtFieldList"
    runat="server"
/>
<asp:requiredfieldvalidator 
    id="rfvFieldList"
    controltovalidate="txtFieldList"
    display="Dynamic"
    font-name="Tahoma"
    font-size="10pt"
    runat=server>
    Field list is required!
</asp:requiredfieldvalidator>
<BR>
From (Table Name)
<BR>
<asp:textbox
    id="txtTableName"
    runat="server"
/>
<asp:requiredfieldvalidator 
    id="rfvTableName"
    controltovalidate="txtTableName"
    display="Dynamic"
    font-name="Tahoma"
    font-size="10pt"
    runat=server>
    Field list is required!
</asp:requiredfieldvalidator>
<BR>
Where (Optional)
<BR>
<asp:textbox
    id="txtWhere"
    runat="server"
/>
<BR>
Order By (Optional)
<BR>
<asp:textbox
    id="txtOrder"
    runat="server"
/>
<BR>
<asp:button 
    id="butOK"
    text="  OK  "
    OnClick="SubmitBtn_Click" 
    runat="server"
/>
<BR><BR>
<asp:datagrid
    id="dgQuery" 
    runat="server" 
    autogeneratecolumns="True"
/>
</form>
</BODY>
</HTML>       
       








EmpDB.zip( 8 k)

Related examples in the same category