I have a search form in a website where I have to do a search in all or one column to database. I have the following stored procedure and have problem with datetime. How will I do to allow it to be null?
I have problem with this both in stored procedure and i codebehind c#.
Hope you can help me!
ALTER PROCEDURE [dbo].[SearchPostit] (
@message varchar(1000)='',
@writer varchar(50)='',
@mailto varchar(100)='',
@date Datetime ) AS
SELECT P.Message AS Postit,
P.Mailto AS 'Mailad till',
P.[Date] AS Datum ,
U.UserName AS Användare
FROM PostIt P LEFT OUTER JOIN
[User] U ON P.UserId=U.UserId
WHERE P.message LIKE '%'+@message+'%' AND P.Mailto LIKE '%'+@mailto+'%'
AND P.Date LIKE '%'+@date+'%' AND U.UserName LIKE '%'+@writer+'%'
GROUP BY P.Message, P.Mailto, P.[Date], U.UserName
This is my codebehind when click on search button. But I got errormessage if no date is in textbox.... Postit p = new Postit(); DateTime dt=DateTime.Parse(TextBoxDate.Text); p.SearchPostit(TextBoxMessage.Text, TextBoxWriter.Text, TextBoxMailto.Text,dt);