使用vb.net的Web应用程序的高级搜索页面

时间:2010-12-08 07:14:07

标签: asp.net vb.net web-applications search advanced-search

我为Web应用程序创建了一个简单的高级搜索页面,我认为与您分享可能对初学者有帮助

以下是使用VB.Net

的员工数据库的高级搜索页面的示例

alt text

以下是页面背后的代码

Imports System.Data.OleDb

Partial Class searchme
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim mydb As New OleDbConnection
    mydb = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= |datadirectory|employee.mdb;Persist Security Info=True")
    mydb.Open()

    Dim sqlstring = "select * from [dataview] where "

    If MRNTextBox1.Text <> "" Then sqlstring = sqlstring + "[code] like '%" + CodeNameTextBox1.Text + "%' OR [EmployeeName] like '%" + CodeNameTextBox1.Text + "%' AND "


    If GOVDDL.SelectedItem.Text <> "--Please Select--" Then sqlstring = sqlstring + "[Governorate] ='" + GOVDDL.SelectedItem.Text + "' AND "
    If genderddl.SelectedItem.Text <> "--Please Select--" Then sqlstring = sqlstring + "[Gender] ='" + genderddl.SelectedItem.Text + "' AND "
    If DateEmploymentFrom.Text <> "" And DateEmploymentTo.Text <> "" Then sqlstring = sqlstring + "[DateEmployment] >= #" + DatumKonvert1.DK1(DateEmploymentFrom.Text) + "# AND [Datepresentation] <= #" + DatumKonvert1.DK1(DateEmploymentTo.Text) + "# AND "
    If DepartmentDDL.SelectedItem.Text <> "--Please Select--" Then sqlstring = sqlstring + "[Department] ='" + DepartmentDDL.SelectedItem.Text + "' AND "


    sqlstring = Left(sqlstring, Len(sqlstring) - 5) + " order by " + OrderByDDL.SelectedItem.Text


    Dim myds As New AccessDataSource
    myds.DataFile = "~\App_Data\employee.mdb"
    myds.SelectCommand = sqlstring


    ' Dim Mygrid As New GridView

    Mygrid.DataSource = myds

    Mygrid.DataBind()


    ' Me.form1.Controls.Add(Mygrid)


    mydb.Close()

    RecCount.Text = "Filtered Record Count = " + mygrid.Rows.Count.ToString
    Session("dsource") = myds
    Response.Redirect("sresults.aspx")


End Sub
End Class

1 个答案:

答案 0 :(得分:1)

你做得很好,也尝试以下

link text

link text