Ahmed Khalid

Ahmed Khalid

  • NA
  • 114
  • 5.4k

GridView Select Enquiry

Jan 26 2023 3:28 AM

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:

<div class="form-group">

                                    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">

                                        <Columns>

                                            <asp:BoundField DataField="FullName" HeaderText="Name" SortExpression="FullName" ItemStyle-Width="100" />

                                            <asp:BoundField DataField="PDate" HeaderText="PDate" SortExpression="PDate" DataFormatString="{0:d}" ItemStyle-Width="150" />

                                            <asp:BoundField DataField="PType" HeaderText="PType" SortExpression="PType" ItemStyle-Width="150" />

                                            <asp:BoundField DataField="PStatus" HeaderText="PStatus" SortExpression="PStatus" ItemStyle-Width="200" />

                                            <asp:BoundField DataField="TransTimeStamp" HeaderText="Time Stamp" SortExpression="TransTimeStamp" ItemStyle-Width="200" />

                                            <asp:BoundField DataField="PName" HeaderText="Guardian" SortExpression="PName" ItemStyle-Width="100" />

                                        </Columns>

                                    </asp:GridView>

                                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:akkdbConnectionString %>"

                                        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"></asp:SqlDataSource>

                                    </div>

 

Kindly advise.

Thanks


Answers (2)