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

How to fix a SQL statement that is not working properly?

The winform has a datetimepicker 4 regular texboxes and 2 masked texboxes and a bound datagridview.

I'm using the cellformatting event of the datagridview to lookup the employees' names from another datatable. To accomplish this I'm using a sql statement that for the most part is working.

As it is right now it returns the employees names from different columns on the second datatable and sets them in the second column of the datagridview right after employee ID as intended.

The part that is NOT working is looking at the termination date ("FSalida" column) and returning the employees name only if it doesn't have a termination date or the selected date is earlier than the termination date. In other words if the employee has been terminated it shouldn't appear after the termination date.

The code that I have is this:

Expand|Select|Wrap|Line Numbers
  1.  Private Sub PartePersonalDataGridView_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
  2.     'This looks up the employee's full name using the employee number from the ID column (first column) 
  3.     Try
  4.         Dim dgvr As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
  5.         If dgvr.Cells(0).Value IsNot Nothing AndAlso dgvr.Cells(0).Value IsNot DBNull.Value Then
  6.             Dim empID As Integer = CInt(dgvr.Cells(0).Value)
  7.             Dim qry = From dr As PersonalObraDataSet.PersonalObRow In PersonalObraDataSet.PersonalOb
  8.             Where (dr.cdTrabajador = empID) And ((dr.FSalida = Nothing) Or (dr.FSalida <= txtDate.Text))
  9.             'This returns each part of the name and joins it in the the 2nd column (name column)
  10.             DataGridView1.Rows(e.RowIndex).Cells(1).Value = (qry.First.Nombre1 & " " & qry.First.Nombre2 & " " & qry.First.Apellido1 & " " & qry.First.Apellido2)
  11.             DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = DefaultBackColor
  12.         End If
  13.         'If there is an exemption like the employee doesn't exists this turns the background color red and instead
  14.         'of the name on the second column it shows "employee doesn't exist."
  15.     Catch ex As Exception
  16.         DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Red
  17.         DataGridView1.Rows(e.RowIndex).Cells(1).Value = "ESTE EMPLEADO NO EXISTE"
  18.         Exit Sub
The part that is not working is after the "And":

Expand|Select|Wrap|Line Numbers
  1. Where (dr.cdTrabajador = empID) And ((dr.FSalida = Nothing) Or (dr.FSalida <= txtDate.Text))
Jul 30 '13 #1
1 1171
Killer42
8,435 Expert 8TB
Could you be more specific as to how it's "not working"? Does it:
  • Produce an error? (Please provide details)
  • Return the wrong set of records?
  • Fail to return any records?
  • Return all records?
A couple of other details might also prove useful:
  • The field type of FSalida;
  • An example of the exact text in txtDate.
Not having a lot of experience in this area myself, I wonder whether Nothing is the correct test there - perhaps it should be Null? (I don't know, I'm just trying out ideas).
Jul 31 '13 #2

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

Similar topics

8
by: weasel | last post by:
Why is the Farenheit to Celsius part not working properly? Instead of showing a similar range of what the farenheit is listing, the celsius portion is showing half the range of farenheit. print...
1
by: Roberto Castro | last post by:
I have some problems with the way I am showing the BLOB fields in the Image web controls. It does work on my localhost though sometimes I need to hit Refresh for the images to load properly....
5
by: Nita Raju | last post by:
Hi, I have to validate a textbox for date without using the validation controls. So i had to use IsDate(). It's not working properly when i give "11//2004". When i enter the above date it...
2
by: Annu | last post by:
Hi I need help on <enbed> tag. Following code(No 1) is working properly on windows but on linux code no.2 is not working Code No 1: <EMBED type='application/x-mplayer2' ...
12
kamill
by: kamill | last post by:
I have done a logout page for logout from admin section and provides a link to logout from admin section.Whenever i clicked on logout link it redirected to index.php of admin section......BUT when i...
5
by: damezumari | last post by:
When a user logs in to my site http://iwantyourquestion.com I set $_SESSION to true if his username and password are OK. When he calls a page I check if $_SESSION is true. If it not I ask him to...
3
by: rajasree | last post by:
Hi all, am doing a project in PHP. my javascript code is working properly in ie. But its not working in firefox. Please help me my code is as follows; <script language="javascript"...
4
by: zairali | last post by:
Hi, I am trying to fix a webpage ( http://www.d.umn.edu/itss/labs/maps/ ) which uses some html (or xml also?) to show pop ups when you rollover the numbers on a map of the building. They work fine...
1
by: robin1983 | last post by:
Dear All, I got stuck in simple problem, I have a two php file one for registration form and one for to check and insert into the table. The problem is that when I get any kind error in...
8
by: neovantage | last post by:
Hey all, Website page is not working properly in IE6 and IE7 but working normal in firefox. Can somebody tell me how i can fixed that problem. Here is the url of the page http://www.ragehockey.biz/...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.