473,386 Members | 1,694 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,386 software developers and data experts.

Dropdownlist NULL

OuTCasT
374 256MB
Please help i have this query that works with drop downlist selections on a page to search for the information selected in the listboxes.
but having a problem when the selection is "null"

otherwise in query analyser it works 100%

Expand|Select|Wrap|Line Numbers
  1. SELECT  *  FROM [cvinformation] WHERE (([race] = CASE WHEN @race IS NOT NULL THEN @race ELSE [race] END) AND ([province] = CASE WHEN @province IS NOT NULL THEN @province ELSE [province] END) AND ([field] = CASE WHEN @field IS NOT NULL THEN @field ELSE [field] END) AND ([gender] = CASE WHEN @gender IS NOT NULL THEN @gender ELSE [gender] END))
when on the page i choose only 2 values and leave others blank then it does not bring back any information
Mar 17 '08 #1
15 2129
DrBunchman
979 Expert 512MB
If it works 100% in Query Analyser then the problem might lie with the data you are passing to the query. Are you sure that your parameters are being passed as NULL where you would expect them to be?

Dr B
Mar 17 '08 #2
ck9663
2,878 Expert 2GB
Please help i have this query that works with drop downlist selections on a page to search for the information selected in the listboxes.
but having a problem when the selection is "null"

otherwise in query analyser it works 100%

Expand|Select|Wrap|Line Numbers
  1. SELECT  *  FROM [cvinformation] WHERE (([race] = CASE WHEN @race IS NOT NULL THEN @race ELSE [race] END) AND ([province] = CASE WHEN @province IS NOT NULL THEN @province ELSE [province] END) AND ([field] = CASE WHEN @field IS NOT NULL THEN @field ELSE [field] END) AND ([gender] = CASE WHEN @gender IS NOT NULL THEN @gender ELSE [gender] END))
when on the page i choose only 2 values and leave others blank then it does not bring back any information

Have you tried ISNULL ?

Also, try to display the sqlstring in a messagebox or something then paste it in query analyzer. Another place you want to look at is, if the object on your GUI is returning NULL by default if you're not selecting anything.

-- CK
Mar 17 '08 #3
OuTCasT
374 256MB
If it works 100% in Query Analyser then the problem might lie with the data you are passing to the query. Are you sure that your parameters are being passed as NULL where you would expect them to be?

Dr B
here is what the dropdownlist boxes on the web form look like.

example of the first one

Expand|Select|Wrap|Line Numbers
  1. <asp:DropDownList ID="drpProvince" AppendDataBoundItems=True runat="server" Width="120px" BackColor="WhiteSmoke" Visible="False">
  2.                         <asp:ListItem Selected="True">-Select-</asp:ListItem>
  3.                         <asp:ListItem>Gauteng</asp:ListItem>
  4.                         <asp:ListItem>Free State</asp:ListItem>
  5.                         <asp:ListItem>KwaZulu Natal</asp:ListItem>
  6.                         <asp:ListItem>Mpumalanga</asp:ListItem>
  7.                         <asp:ListItem>Limpopo Province</asp:ListItem>
  8.                         <asp:ListItem>Northen Cape</asp:ListItem>
  9.                         <asp:ListItem>Eastern Cape</asp:ListItem>
  10.                         <asp:ListItem>Western Cape</asp:ListItem>
  11.                         <asp:ListItem>North West</asp:ListItem>
  12.                     </asp:DropDownList>
Mar 18 '08 #4
OuTCasT
374 256MB
Have you tried ISNULL ?

Also, try to display the sqlstring in a messagebox or something then paste it in query analyzer. Another place you want to look at is, if the object on your GUI is returning NULL by default if you're not selecting anything.

-- CK
so what i should do is put the string into a variable and then call the variable in a messagebox to see what is being displayed correct. ?
Mar 18 '08 #5
OuTCasT
374 256MB
Have you tried ISNULL ?

Also, try to display the sqlstring in a messagebox or something then paste it in query analyzer. Another place you want to look at is, if the object on your GUI is returning NULL by default if you're not selecting anything.

-- CK

ISNULL does not work unfortunately
Mar 18 '08 #6
DrBunchman
979 Expert 512MB
so what i should do is put the string into a variable and then call the variable in a messagebox to see what is being displayed correct. ?
Yes, once you've got the string you can run it in query analyser and see where the problem is occurring. I would guess the problem to be that you are passing "" instead of NULL values for these parameters but you'll be able to find our for yourself.

Good luck,

Dr B
Mar 18 '08 #7
OuTCasT
374 256MB
Yes, once you've got the string you can run it in query analyser and see where the problem is occurring. I would guess the problem to be that you are passing "" instead of NULL values for these parameters but you'll be able to find our for yourself.

Good luck,

Dr B
Hi Dr B.

Yes i agree that the problem is with the drop downs.....they are using " " as a value instead of NULL so nothing is being processed.

Im using a Gridview to display some data and from there they choose to view the specific row etc....
now when i configure the datasource for the gridview with that SQL query i posted earlier, i go to TEST QUERY and i only enter like 1 value and leave the others empty and it works....

Im going to have to find another solution to this problem because the bosses want the search thing upp and running already ..... :'(
Mar 19 '08 #8
OuTCasT
374 256MB
Yes, once you've got the string you can run it in query analyser and see where the problem is occurring. I would guess the problem to be that you are passing "" instead of NULL values for these parameters but you'll be able to find our for yourself.

Good luck,

Dr B
Hi again...
When testing the query i noticed that the query is ACTUALLY looking for NULL values in the columns......most of the columns do not have NULL values because they are populated with values.
Thats why no information was being returned....
Now i need to change the query so that instead of LOOKING for NULL values it just brings back the values if null is inserted....
i dont knw if that makes any sense.
Mar 19 '08 #9
DrBunchman
979 Expert 512MB
Sorry OuTCasT, I don't really understand what the problem is....can you try and explain it again?

Are you still using the same sql string? If not can you print the new one.

Ta muchly,

Dr B
Mar 19 '08 #10
OuTCasT
374 256MB
Sorry OuTCasT, I don't really understand what the problem is....can you try and explain it again?

Are you still using the same sql string? If not can you print the new one.

Ta muchly,

Dr B
hehe ok here goes.

I have the 4 drop down list boxes on the page.
they are not bound to the db they are static values but equal to what is in the db.
ok here is the query that im using.

Expand|Select|Wrap|Line Numbers
  1. SELECT  *  FROM [cvinformation] WHERE (([race] = CASE WHEN @race IS NOT NULL THEN @race ELSE [race] END) AND ([province] = CASE WHEN @province IS NOT NULL THEN @province ELSE [province] END) AND ([field] = CASE WHEN @field IS NOT NULL THEN @field ELSE [field] END) AND ([gender] = CASE WHEN @gender IS NOT NULL THEN @gender ELSE [gender] END))
Ive got a page that lets users load there cv information.
and then i have a page that uses the dropdownlistboxes to search for the information and populates a gridview with that information, the gridview is selectable.

Now the problem is i have to use all 4 dropdownlist boxes in order to get the data to display.
We thought i was the dropdownlist boxes not passing " NULL " to the database.
But when i was checkin the page and searching with the dropdownlist boxes i saw that the SQL QUERY is LOOKING for NULL values in the database.....thats not wat i want.
because most users enter all criteria on the cv...
im searching for

Gender:
Field of study:
Race:
Location:

and when i was testing i saw if i entered gender, race and location it would bring up 2 names....because those name had null values as there field of study so i came to the conclusion that the query was indeed looking for null values in the database.....and when i was leaving the dropdownlists values null it was not bring back information because there is no one in the database that has null values for gender, field of study, race and location.

what i want is for example :
say i choose

Gender: Male
Field of Study: Accounting
Race: "null"
Location: Queensland

Then i want all males who do accounting and live in queensland.......but i cant seem to get that right...

another example

Gender:"null"
Field of study:"null
Race: "null"
Location:"null"

if i selected something like that then i would like ALL the records in that table to be returned into the gridview...

PLEASE HELP......lol
Mar 19 '08 #11
DrBunchman
979 Expert 512MB
How do you run your query? Is it in a stored procedure or do you define it as a sql string and run it from your code?
Mar 20 '08 #12
OuTCasT
374 256MB
How do you run your query? Is it in a stored procedure or do you define it as a sql string and run it from your code?
hi Dr B

the query is run on the click event of the submit button and the query is binded to the gridview.
Mar 20 '08 #13
OuTCasT
374 256MB
How do you run your query? Is it in a stored procedure or do you define it as a sql string and run it from your code?
if i go through the datasource wizard of the gridview and insert my query string just before finishing u can TEST QUERY.... and when i test it in there it works 100%....even with no values.....i dont get it.
Mar 20 '08 #14
OuTCasT
374 256MB
hi Dr B

the query is run on the click event of the submit button and the query is binded to the gridview.
Dr B

i found the error.

there was something wrong with the settings for the dropdownlist boxes....CONVERTSTRINGTONULL = true

and i changed the field variable from EMPTY to STRING
and its working 100%

thanks for ur help guy
Mar 20 '08 #15
DrBunchman
979 Expert 512MB
Dr B

i found the error.

there was something wrong with the settings for the dropdownlist boxes....CONVERTSTRINGTONULL = true

and i changed the field variable from EMPTY to STRING
and its working 100%

thanks for ur help guy
No probs, glad you got it sorted
Mar 21 '08 #16

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

Similar topics

2
by: rmorvay | last post by:
I am trying to dynamically build a dropdownlist and bind it to a cell in a grid. I tried to utilize the following code but I am stuck at the point where I bind the dropdownlist to the grid cell. ...
4
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the...
0
by: R.A.M. | last post by:
Hello, Could you help me please to define GridView associated to DropDownList. My DropDownList "Publishers" should show publishers' names from SQL Server table Publishers. My GridView...
1
by: R.A.M. | last post by:
Hello, Could you help me please to define GridView associated to DropDownList... My DropDownList "Publishers" should show publishers' names from SQL Server table Publishers. My GridView...
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
3
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.) I have two DropDownList controls the...
0
by: lamolap | last post by:
i have 1 gridview , a dropdownlist inside a gridview and a commandfield of (edit, update and cancel) my gidview looks like this Edit Surname Initials ...
18
by: Redhairs | last post by:
Is it possible to get DropDownList.SelectedValue in Page_PreInit() event during the postback?
1
by: shapper | last post by:
Hello, I am trying to display a DropDownList on an ASP.NET MVC view. SlidePaper.Targets contains the list of items and SlidePaper.Slide.Target contains the current value taken from the...
0
by: stevem2112 | last post by:
I have a datagrid with 2 Template columns. One column has DropDownLists and the other has Textboxes. I bind each DDL in the ItemCreated event. This datagrid is inside a UserControl that is inside...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.