473,288 Members | 1,718 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,288 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 1166
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
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.