Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,
I'm on a learning journey and now i have reached the point of passing parameters from an ASP websiteform into my SQL Query. But how do I get that?
I would like to have either 2 textboxes or listboxes where the user can request year and month for getting finansial turnover.

But how do I get that into the Query and bind the Query to my input controls?

My code is as follows:

Remark my current input code which is named UserInputYEAR and UserInputMonth

What I have tried:

SQL
SELECT        CAST(SUM(Cust.[Sales (LCY)]) AS decimal(8, 2)) AS Totalsales, Cust.[Customer No.], Customer.Name, Customer.[Sell-to Type]
FROM            [Cust. Ledger Entry] AS Cust INNER JOIN
                         Customer ON Cust.[Customer No.] = Customer.[No.]
WHERE        (YEAR(Cust.[Posting Date]) = UserInputYEAR and (MONTH(Cust.[Posting Date]) = UserInputMONTH
GROUP BY Cust.[Customer No.], Customer.Name, Customer.[Sell-to Type]
ORDER BY Totalsales DESC
Posted
Updated 9-Feb-16 1:10am
v2
Comments
CHill60 9-Feb-16 7:11am    
Are you constructing this query in your ASP application or is it a stored procedure on the database which you are calling
Kristian_dk 9-Feb-16 7:27am    
I am constructing this in my asp application by dragging in a DataGridView and then configuring the datasource by a SQL Query.
Hope this makes sense.

It depends what you use to access your database. If you're using ado.net then have a look through this;

Parameterized Queries ADO.Net[^]
 
Share this answer
 
Comments
Kristian_dk 9-Feb-16 7:21am    
My connectionstring looks like this:

<asp:SqlDataSource ID="SqlDataSource1701" runat="server" ConnectionString="<%$ ConnectionStrings:WebCrmMsAzureConnectionString %>" SelectCommand="SELECT CAST(SUM(Cust.[Sales (LCY)]) AS decimal(8 , 2)) AS Totalsales, Cust.[Customer No.], Customer.Name, Customer.[Sell-to Type] FROM [Cust. Ledger Entry] AS Cust INNER JOIN Customer ON Cust.[Customer No.] = Customer.[No.] WHERE (YEAR(Cust.[Posting Date]) = YEAR(GETDATE())) GROUP BY Cust.[Customer No.], Customer.Name, Customer.[Sell-to Type] ORDER BY Totalsales DESC">
F-ES Sitecore 9-Feb-16 8:03am    
I wouldn't bother with things like asp:SqlDataSource, you should learn to bind your controls via code-behind, it gives you far greater flexibility and power.
Kristian_dk 9-Feb-16 7:21am    
is this a ADO.net access?
Hi you can look this code and refer in your code this will help you

ASP.NET
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" SelectCommand="SELECT * FROM [UserMaster] WHERE ([EMPID] = @EMPID)">
            <SelectParameters>
                <asp:ControlParameter ControlID="TextBox1" Name="EMPID" PropertyName="Text" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900