locked
Manipulate SQL Query via Form on ASP.NET C# MVC RRS feed

  • Question

  • I have a project where I have a form with 2 date input fields. Once they are filled in the user will click the generate button which in turn should manipulate the SQL script and change 2 dates on it. I am just wondering if this is possible if so could someone please point me towards the correct method please?

    Thankyou 

    • Moved by Fei Hu Tuesday, February 6, 2018 2:01 AM From C#
    Friday, February 2, 2018 2:39 PM

All replies

  • The SELECT should be something like SELECT FirstName FROM Customers WHERE Date1 = @Date1 AND Date2 = @Date2

    Then for your SqlClient command add two parameters e.g.

    cmd.Parameters.AddWithValue("@Date1",someDate) and the same for the second date. If using Entity Framework 

    dbContext.Customers.Where( cust => cust.Date1 == someDate && cust.Date2 == otherDate).Select(cust => cust);


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, February 2, 2018 3:02 PM
  • Please post questions related to ASP.NET, MVC and web development in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Friday, February 2, 2018 3:12 PM
  • If you are talking ASP.NET MVC, then you must be using EF code first, and if so, then you would have to go through EF to do it.

    As mentioned, you need to post to the MVC forum in ASP.NET forums,  and also, there are forums for EF and MS SQL Server T-SQL too in the ASP.NET forums.

    http://forums.asp.net/

    Friday, February 2, 2018 5:10 PM
  • Hi JasonReynolds92,

    This forum is discussing and asking the C# programming language, IDE, libraries, samples and tools, it will be more appropriate to ask your question at ASP.NET Forum.

    Thank you for your understanding.

    Regards,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 5, 2018 7:19 AM