Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

advanced search

Status
Not open for further replies.

damipera

Technical User
Dec 1, 2005
134
GB
Hi guys! I would like to write an advanced search application in ASP.net VB but am not too sure how. What I want is to give them options if they want to search for all words, any word, or exact phrase. Very much like this one I've found but is written in asp.



Any help is appreciated. Thanks guys!
 
Hopefully this will give you a clue .....it is very simple example but it helps me learing how to create an advanced search page. good luck
Imports System.Data
Imports System.Data.OracleClient
Imports System.Configuration.ConfigurationManager
Partial Class ItemSearch
Inherits System.Web.UI.Page


Sub SearchButton_Click(ByVal sender As Object, ByVal e As EventArgs)

'Dim oOracleConn As OracleConnection
Dim connectionString As String = ConnectionStrings("ConnectionString").ConnectionString
Dim oOracleConn As OracleConnection = New OracleConnection(connectionString)

'This will make sure both english and metric units are not selected at the same time.
If (ck2005.Checked And ck2001.Checked) Or (ck2000.Checked And ck2001.Checked) Or (ck2005.Checked And ck2001.Checked And ck2000.Checked) Then
lblMixUnit.Text = "You can not select both English and Metric units at the same time"
gvItemSearch.Visible = False
lblTotal.Visible = False
lblMixUnit.Visible = True
Else

gvItemSearch.Visible = True
lblTotal.Visible = True
lblMixUnit.Visible = False
Dim strWhereClause As String = ""
'converts the input value to uppercase
strWhereClause = Trim(UCase(txtItem.Text))

Dim strSQLforGrid As String = "SELECT Item_Number ""Item Number"" , "
strSQLforGrid = strSQLforGrid & " Short_Description ""Short Description"", LONG_DESCRIPTION ""Long Description"",UNIT_NAME ""Unit Name"" , "
strSQLforGrid = strSQLforGrid & " PLAN_UNIT_DESCRIPTION ""Plan Unit Description"", SPEC_YEAR ""Spec Year"" "
strSQLforGrid = strSQLforGrid & " FROM ITEMSEARCH"
strSQLforGrid = strSQLforGrid & " WHERE ITEM <> '2999509/00001' AND IOBSELET='N' AND "

'search by either description or units
If rdDes.Checked Then
strSQLforGrid = strSQLforGrid & "upper(LONG_DESCRIPTION) Like :vendID"
ElseIf rdUnit.Checked Then
strSQLforGrid = strSQLforGrid & "upper(PLAN_UNIT_DESCRIPTION) like :vendID"
ElseIf rdNumber.Checked Then

strSQLforGrid = strSQLforGrid & "upper(Item_Number ) like :vendID"
End If

'checks with spec year(s) is/are selected
If (ck2005.Checked And ck2000.Checked) Then
strSQLforGrid = strSQLforGrid & " and (SPEC_YEAR = '05' or SPEC_YEAR= '00')"
ElseIf ck2000.Checked Then
strSQLforGrid = strSQLforGrid & " and SPEC_YEAR = '00'"
ElseIf ck2001.Checked Then
strSQLforGrid = strSQLforGrid & " and SPEC_YEAR = '01'"
ElseIf ck2005.Checked Then
strSQLforGrid = strSQLforGrid & " and SPEC_YEAR = '05'"
Else : strSQLforGrid = strSQLforGrid & " and SPEC_YEAR = '05'"
End If
strSQLforGrid = strSQLforGrid & " order by Item_Number asc,LONG_DESCRIPTION asc "

'Remove next line prior to deployment
'Response.Write("strSQLforGrid = <br/>" & strSQLforGrid & "<hr/>")

Dim myCommand3 As OracleCommand = New OracleCommand(strSQLforGrid, New OracleConnection(GetConnectionString()))
myCommand3.Parameters.Clear() 'Clear the parameters
myCommand3.Parameters.AddWithValue(":vendID", "%" & strWhereClause & "%")
Dim myAdapter3 As New OracleDataAdapter(myCommand3)

Dim myDataSet As New DataSet
myAdapter3.Fill(myDataSet, "VendorSearch")

gvItemSearch.DataSource = myDataSet
gvItemSearch.DataBind()

lblTotal.Text = "Total :" + gvItemSearch.Rows.Count.ToString() + " record(s) found"
End If

End Sub
Function GetConnectionString() As String
Return ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
End Function

End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top