473,383 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

SQL Query and .Net code for Advanced search in my application ??

Hi,

I have 1 checkboxlist, 5 dropdownlits and three textboxes.I have to write the SQL query and c# code for that advanced search.

Expand|Select|Wrap|Line Numbers
  1. <asp:CheckBoxList ID="reposotoryCheckBoxList" runat="server" Style="z-index: 106; left: 226px;position: absolute; top: 18px"> 
  2. asp:ListItem Text="computer" Value="2"></asp:ListItem>
  3.  
  4. <asp:ListItem Text="math" Value="3"></asp:ListItem>
  5.  
  6. <asp:ListItem Text="science" Value="1"></asp:ListItem>--%>
  7.  
  8.  
  9. </asp:CheckBoxList><asp:DropDownList ID="DropDownList1" runat="server"> 
  10. <asp:ListItem>Anywhere</asp:ListItem>
  11.  
  12. <asp:ListItem>Title Words</asp:ListItem>
  13.  
  14. <asp:ListItem>Creator Name Words</asp:ListItem>
  15.  
  16. <asp:ListItem>Subject Words</asp:ListItem>
  17.  
  18. </asp:DropDownList>
  19.  
  20. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
  21.  
  22. <asp:DropDownList ID="DropDownList2" runat="server">
  23.  
  24. <asp:ListItem>and</asp:ListItem>
  25.  
  26. <asp:ListItem>or</asp:ListItem>
  27.  
  28. <asp:ListItem>not</asp:ListItem>
  29.  
  30. </asp:DropDownList>
  31.  
  32. <asp:DropDownList ID="DropDownList3" runat="server">
  33.  
  34. <asp:ListItem>Anywhere</asp:ListItem>
  35.  
  36. <asp:ListItem>Title Words</asp:ListItem>
  37.  
  38. <asp:ListItem>Creator Name Words</asp:ListItem>
  39.  
  40. <asp:ListItem>Subject Words</asp:ListItem>
  41.  
  42. </asp:DropDownList><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
  43.  
  44. <asp:DropDownList ID="DropDownList4" runat="server">
  45.  
  46. <asp:ListItem>and</asp:ListItem>
  47.  
  48. <asp:ListItem>or</asp:ListItem>
  49.  
  50. <asp:ListItem>not</asp:ListItem>
  51.  
  52. </asp:DropDownList>
  53.  
  54. <asp:DropDownList ID="DropDownList5" runat="server">
  55.  
  56. <asp:ListItem>Anywhere</asp:ListItem>
  57.  
  58. <asp:ListItem>Title Words</asp:ListItem>
  59.  
  60. <asp:ListItem>Creator Name Words</asp:ListItem>
  61.  
  62. <asp:ListItem>Subject words</asp:ListItem>
  63.  
  64. </asp:DropDownList><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
  65.  

The dropdown list items are from different table, Title from tblTitle,Subject from tblSubject and createrName from tblName.

Any help will be highly appreciated.

Thanks
Nov 11 '08 #1
2 1610
Frinavale
9,735 Expert Mod 8TB
It's wonderful that you have to write an advanced search feature. You've created the interface for it but it appears that you haven't attempted to implement any functionality for searching.

The experts on this site are more than happy to help you with your problems... but they cannot do your assignment/program for you.

Attempt the program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

-Frinny
Nov 11 '08 #2
Hi Frinny,

Thanks for the reply. I did this and I have problem to select the different table from dropdownlist.

here is my sql query:(inside the App_Code)

public static DataSet GetReport(String repository, String name, String title, String subject)
{


String sql = " Select distinct col.ID,col.CollectionAbstract,col.Title,col.SortTi tle,col.Scope,col.CollectionIdentifier from tblCollections_Collections col" +
" LEFT JOIN tblCollections_CreatorIndex colCI " +
" ON col.ID = colCI.CollectionID " +
" LEFT JOIN tblCreators_Creators cr" +
" ON colCI.CreatorID = cr.ID " +
" LEFT JOIN tblCollections_SubjectIndex sbI " +
" ON col.ID = sbI.CollectionID " +
" LEFT JOIN tblSubjects_Subjects sub " +
" ON sbI.SubjectID = sub.ID " +
" where ( 1=1 )" + //
(repository == null || repository.Trim() == "" ? "" : " and col.RepositoryID in( " + repository + " )") +
(title == null || title.Trim() == "" ? "" : " and col.Title like '%" + title + "%'") +
(name == null || name.Trim() == "" ? "" : " and cr.Name like '%" + name + "%'") +
(subject == null || subject.Trim() == "" ? "" : " and sub.Subject like '%" + subject + "%'")+
" order by col.Title";




return SqlHelper.ExecuteDataset(GetConnectionString(), CommandType.Text, sql);
}



aspx.cs file contains:

protected void Button1_Click(object sender, EventArgs e)

{

try
{

String repository = "";
Boolean first = false;


if (reposotoryCheckBoxList.Items[0].Selected == true)
{
repository = " 1,3,5";
}

else
{
first = false;
for (int i = 0; i <= reposotoryCheckBoxList.Items.Count - 1; i++)
{
if (reposotoryCheckBoxList.Items[i].Selected == true)
{
if (first == false)
{
repository = reposotoryCheckBoxList.Items[i].Value.ToString();
first = true;
}
else
{
repository = repository + " , " + reposotoryCheckBoxList.Items[i].Value.ToString();

}
}
}

}

......My questions .....how to implement that 5 dropdownlists here..............???.......

string str = TextBox1.Text.ToString();
string str1 = TextBox2.Text.ToString();
string str2 = TextBox3.Text.ToString();
str = str.Trim();
str1 = str1.Trim();
str2 = str2.Trim();


//throw new Exception();
DataSet ds;
ds = DataAccess.GetReport(repository, str1, str, str2);
Repeater1.DataSource = ds;
Repeater1.DataBind();

}
Nov 11 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
3
by: eddie wang | last post by:
Hello, I am working on an Access database. For some strange reason, my query keeps getting erased by itself. The SQL view of my query object looks like this: SELECT * FROM emp WHERE...
9
by: deko | last post by:
I need to create a Recordset of all records that appear in one table but do NOT appear in another. To get the records that appear in BOTH tables, I can do this: SELECT tblEntity.Entity_ID...
5
by: ric_deez | last post by:
Hi there, I would like to create a simple search form to allow users to search for a job number based on a number of parameters. I think I understand how to use parameteres associated with Stored...
6
by: sara | last post by:
I hope someone can help with this. Our director wants to have a report that will have the departments (Retail stores) across the top, stores down the side and the RANKING of the YTD dept sales...
3
by: olafbrungot | last post by:
I get the following error message when trying to connect to a host database (OBCD connection) with "MS Query". SQL0471N Invocation of routine "SYSIBM .SQLTABLES " failed due to reason...
10
by: Jerim79 | last post by:
I need to take the output from a query and convert it to lower case. Here is the relevant code: $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND LNAME=('$LName')"; $result =...
8
by: fel | last post by:
does anybody know of any *web* query builder in PHP, something like the Access query builder, or similar, done in PHP or similar? I've looked for it trough the net, but nothing is colse to what I...
3
by: pbd22 | last post by:
Hi. I need some help with structuring my query strings. I have a form with a search bar and some links. Each link is a search type (such as "community"). The HREF for the link's anchor looks...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.