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

发布于 2024-10-06 06:26:42 字数 2061 浏览 1 评论 0原文

我为 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

i created a simple advanced search page for web application, i thought sharing it with you might help beginners

the following is an example of an advanced search page for an employee database using VB.Net

alt text

the following is the code behind page

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩发小公举 2024-10-13 06:26:42

你做得很好,还可以尝试以下

链接文本

链接文本

you did a good job, also try the following

link text

link text

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文