Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have database tables : customer, customertranscations and transactions.
I want to create a dropdown list with the customer name and then on selection of a specific customer i want to view the purchase details of the customer that they have purchased within the last 31 days. I have completed the query part but i am having hard time figuring out how to do this.
I want to display it in datagridview but not use sqldatasource and use the visual studio GUI to do it all. I want to try using stored procedure.

What I have tried:

SELECT c.customer_id, c.name, t.transactions_date, t.payment_amount 
from customer c INNER JOIN customertranscations ct ON c.customer_id = ct.customer_id 
INNER JOIN transactions t on ct.transactions_id= t.transactions_id WHERE 
t.transactions_date >=DATEADD(DAY, -2, getdate() - 31 ) AND c.customer_id = 'cus1' 
Posted
Updated 4-May-18 1:43am

1 solution

Creating a stored procedure can be, at the level you need it, learned rather quickly from Create a Stored Procedure | Microsoft Docs[^]


The basic format is:
CREATE PROCEDURE SP_NAME_YOU_LIKE (
  @Declare_Input datatype, 
  @moreInput     datatype,
  etc.
)
AS
--  Your SQL Query of any sort.  Use the @values for controlling filters, 
such as
SELECT * FROM Some_Table WHERE colVal=@Declare_Input
 
Share this answer
 
Comments
Subit Timalsina 4-May-18 10:08am    
Actually i meant i can do the stored procedure but i want to know how it can be done from code behind. i am really confused on that
W Balboos, GHB 4-May-18 11:48am    
C# has a namespace for access to the databases
- build the query that calls your stored procedure and use it.
- when the results come back - do what you want with them.

You "WANT" a lot - well, then start looking up how to do it! You have amazing resources available to you with the internet. I taught myself to do these things from real books - limited resources - and a lot of resolve. You need to make the effort - which is usually hard work.

Also, note that "c.customer_id = 'cus1' " in your query, above, is going to really limit your results!

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