As you can see, I originally did this using accessdatasource, and it worked great. My Client decided to change to SQL as I advised. But I can't figure out how to do this same function with an SQLdatasource. When I change it, I get an error stating "OnSelecting
(just below the CancelSelectOnNullParameter="False" is not part of the SQL something something". Please help.
Thank you. Though, I do not know how to do this in the codebehind, and when I removed the OnSelecting, the code didn't produce any results in my GridView.
FROM tblBusinessRequirements WHERE (@RequirementID IS NULL OR RequirementID LIKE '%' + @RequirementID + '%') AND (@RequirementVersion IS NULL OR RequirementVersion LIKE '%' + @RequirementVersion + '%');"
Jim9674
Member
13 Points
26 Posts
Please translate this code for a SQLdatasource
Oct 08, 2008 06:57 PM|LINK
As you can see, I originally did this using accessdatasource, and it worked great. My Client decided to change to SQL as I advised. But I can't figure out how to do this same function with an SQLdatasource. When I change it, I get an error stating "OnSelecting (just below the CancelSelectOnNullParameter="False" is not part of the SQL something something". Please help.
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/EmblemHealthBRR.mdb" SelectCommand="SELECT RequirementID, RequirementVersion, ProjectName, Department, Rank, RequirementStatus, RequirementStatusReason, ColorCode, Identifiedby, Assignedto, ISStatus, RequirementStatementFROM tblBusinessRequirements WHERE
(@RequirementID IS NULL OR RequirementID LIKE '%' + @RequirementID + '%') AND
(@RequirementVersion IS NULL OR RequirementVersion LIKE '%' + @RequirementVersion + '%');" CancelSelectOnNullParameter="False" OnSelecting="AccessDataSource1_Selecting"> <SelectParameters> <asp:ControlParameter ControlID="txtRequirementID" Name="RequirementID" Type="String" /> <asp:ControlParameter ControlID="txtRequirementVersion" Name="RequirementVersion" Type="String" />
</SelectParameters></
asp:AccessDataSource>limno
All-Star
117340 Points
8005 Posts
Moderator
MVP
Re: Please translate this code for a SQLdatasource
Oct 08, 2008 07:08 PM|LINK
Try to remove the OnSelecting Event in your markup or add the event in your code.
Format your SQL query with instant sql formatter:
http://www.dpriver.com/pp/sqlformat.htm
Jim9674
Member
13 Points
26 Posts
Re: Please translate this code for a SQLdatasource
Oct 08, 2008 07:11 PM|LINK
Thank you. Though, I do not know how to do this in the codebehind, and when I removed the OnSelecting, the code didn't produce any results in my GridView.
limno
All-Star
117340 Points
8005 Posts
Moderator
MVP
Re: Please translate this code for a SQLdatasource
Oct 08, 2008 07:14 PM|LINK
What are you doing in your OnSelecting event?
Format your SQL query with instant sql formatter:
http://www.dpriver.com/pp/sqlformat.htm
limno
All-Star
117340 Points
8005 Posts
Moderator
MVP
Re: Please translate this code for a SQLdatasource
Oct 08, 2008 07:15 PM|LINK
You are talking about SQLDataSource, but you are showing us an AccessDataSource sample.
Format your SQL query with instant sql formatter:
http://www.dpriver.com/pp/sqlformat.htm
Jim9674
Member
13 Points
26 Posts
Re: Please translate this code for a SQLdatasource
Oct 08, 2008 07:16 PM|LINK
It's for my Search button. When it's clicked, it runs the datasource
Jim9674
Member
13 Points
26 Posts
Re: Please translate this code for a SQLdatasource
Oct 08, 2008 07:18 PM|LINK
I know. I'm asking someone to translate the code I have for the accessdatasource into the correct code for the SQLdatasourcelimno
All-Star
117340 Points
8005 Posts
Moderator
MVP
Re: Please translate this code for a SQLdatasource
Oct 08, 2008 07:27 PM|LINK
Do you have a SQL Database in place which holds the table? If you do, you need to create a connection to point to the database.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:yourConnectionString %>" SelectCommand="SELECT RequirementID, RequirementVersion, ProjectName, Department, Rank, RequirementStatus, RequirementStatusReason, ColorCode, Identifiedby, Assignedto, ISStatus, RequirementStatementFROM tblBusinessRequirements WHERE (@RequirementID IS NULL OR RequirementID LIKE '%' + @RequirementID + '%') AND (@RequirementVersion IS NULL OR RequirementVersion LIKE '%' + @RequirementVersion + '%');"
CancelSelectOnNullParameter="False"OnSelecting="AccessDataSource1_Selecting">><SelectParameters>
<asp:ControlParameter ControlID="txtRequirementID" Name="RequirementID" Type="String" /> <asp:ControlParameter ControlID="txtRequirementVersion" Name="RequirementVersion" Type="String" /> </SelectParameters> </asp:SqlDataSource>Format your SQL query with instant sql formatter:
http://www.dpriver.com/pp/sqlformat.htm
Jim9674
Member
13 Points
26 Posts
Re: Please translate this code for a SQLdatasource
Oct 08, 2008 07:51 PM|LINK
Thank you very much. That worked.