stored procedure not recognizing date

CmdDups.Parameters.Add("@LName", SqlDbType.VarChar, 40);
CmdDups.Parameters.Add("@DOB", SqlDbType.SmallDateTime);
CmdDups.Parameters.Add("@Address", SqlDbType.VarChar, 50);

CmdDups.Parameters["@LName"].Value = LName.Text;
CmdDups.Parameters["@DOB"].Value = TxDOB.Text;
CmdDups.Parameters["@Address"].Value = Address.Text;

I have the above stored procedure.  After updates I pass the values to check if the values exist in another table.  I have a record that I have entered that is in the other table.  I am having problems with the DOB field.  When I type "01/12/1946", the parameter runs okay and if identifies that the entry is already in another table.  If I pass the text value of a textbox or datetimepicker the procedure executes fine, but it does not identify that the record is already in the other table.

Please help.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What if you did:

CmdDups.Parameters["@DOB"].Value = Convert.ToDateTime(TxDOB.Text);

does that do anything?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yanci1179Author Commented:
no, it just goes right over it.  I don't get any errors but it does not identify a match with the date that is in the database.  It only makes a match if I actually type "01/12/1946"

any other suggestions?  I have no clue what is wrong!!
yanci1179Author Commented:
this is my stored procedure:

CREATE proc dbo.usp_SEDupCk
(@LName varchar(40),
@DOB smalldatetime,
@Address varchar(50))
SELECT       SE.DtSched, SE.MSI, SE.HH_ID,SE.Barcode , SE.LName, SE.MName, SE.Fname, SE.DOB,
      HH.Address, HH.City, HH.Zip,HH.HmNum, HH.OtherNum
      FROM       tblHH HH, tblSE SE
            (SE.HH_ID = HH.HH_ID AND (lname LIKE '%' + @lname + '%' AND DOB = @dob))
            OR (address LIKE '%' + @address + '%' AND SE.HH_ID = HH.HH_ID)
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

illusioSoftware Architect / Team LeaderCommented:
Comparing a datetime in SQL is always a risky business even if you use the smalldatetime.
The trouble is that the datetime is not exactly the same (differs in hours and minutes - no seconds with smalldatetime).

1) In code:
CmdDups.Parameters["@DOB"].Value = DateTime.ParseExact(TxDOB.Text, "dd/MM/yyyy", new System.Globalisation.DateTimeFormatInfo()).Today;
The Today strips all kind of hour and minute information from the Datetime.

2) In the Stored Proc:
Change: ... DOB = @dob ...
Into: ... DATEDIFF(d, DOB, @dob) = 0 ...

Hope this helps,
change the SP to

AND DOB = @dob)


convert(datetime,convert(char(10),<DOB >,101)=@dob
i mean convert(datetime,convert(char(10),DOB,101)=@dob

if that doesnt work try this

yanci1179Author Commented:
Thanks for the solutions, I'm going to try each one, one at a time.


I tried:

DateTime.ParseExact(TxDOB.Text, "dd/MM/yyyy", new System.Globalization.DateTimeFormatInfo()).Today;

and I got the following error:

Static member 'System.DateTime.Today.get' cannot be accessed with an instance reference; qualify it with a type name instead      
yanci1179Author Commented:
Well, I hate to say this but I tried my original code today and it worked!!??

I'm not sure what happened, I guess I'm going to have to test it a few more time to make sure that it is working.  

thanks again for the help.
illusioSoftware Architect / Team LeaderCommented:

DateTime.ParseExact(TxDOB.Text, "dd/MM/yyyy", new System.Globalization.DateTimeFormatInfo()).Date;

Must have been half sleeping when I typed this...

My appologies,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.