Hi,
I have a grid view in my web form and have implemented the following gridview enquiry whereby i need to select records based on the string value "Txt_PName" and Date Value "PDate", both values are in the form. When I enquire only with the Date, the gridview returns rows but when i add the textbox in the where clause, it returns error as shown below:
System.Data.SqlClient.SqlException: 'Cannot find either column "Txt_ParentName" or the user-defined function or aggregate "Txt_ParentName.Text.Trim", or the name is ambiguous.'
Here is the sample code:
SelectCommand="SELECT [FullName], [PDate], [PType], [PStatus], [PName], [TransTimeStamp] FROM [PTransMaster_Tbl] Where [PDate] = CAST(GETDATE() as date) and PName = Txt_PName.Text.Trim() Order By PDate DESC">
Kindly advise.
Thanks

Sachin SinghRank #66 · 26.2K reputationPosted Jan 26, 2023, 4:55 AM EST
Modify your select command as
" SelectCommand="SELECT [FullName], [PDate], [PType], [PStatus], [PName], [TransTimeStamp] FROM [PTransMaster_Tbl] WHERE [PDate] = CAST(GETDATE() as date)and PName=@PName ORDER BY PDate">Ahmed Khalid185 reputationPosted Jan 26, 2023, 10:56 AM EST
Thank you Sachin. I applied the changes it worked