none
Data with where clause and order by clause relational database RRS feed

  • Question

  • vb.net SQL SERVER

    Database k1

    Table: Customer

    pk-CID | C-Name

           1  |  anzar

            2  | Orva

             3 | Anzar

            4  | Anzar

            5  | Jawad

    Table 2 Sales

    pk-Sid | C-Name | ProductPrice  | unitprice

          1  |  Anzar    |   Z                |    50

          2  |   Anzar   |   p               |   90

           3 |  Orva     |   Z                 |  10     

           4 |  jawad   |   p                 |   50

           5 |  Anzar   |    p                 |  20

    My Requirement

    I want the last unit price of product which is given to anzar  about p or z

    Vb.net Coding problem


    MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959


    • Edited by muhammadanzar Wednesday, January 23, 2019 6:42 PM my fault
    Thursday, January 17, 2019 6:29 PM

All replies

  • In the designer setup a parameter e.g.

    Works no different in a regular SELECT e.g.

    DECLARE @Id AS INT = 2
    
    SELECT cust.CustomerIdentifier,
           cust.CompanyName,
           ord.OrderID,
           ord.OrderDate
    FROM Customers AS cust
         INNER JOIN Orders AS ord ON cust.CustomerIdentifier = ord.CustomerIdentifier
    	 WHERE cust.CustomerIdentifier = @Id
    ORDER BY ord.OrderDate DESC


    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

    Thursday, January 17, 2019 7:44 PM
    Moderator
  • hi

    i think in your code you make a store procedure.  now i want to take the value of @id from vb.net text box.  i use the vb.net  2010.



    MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

    Friday, January 18, 2019 5:30 AM

  • I want the last unit price of product which is given to anzar 

    Vb.net Coding problem

    Dim adapter As New SqlDataAdapter("SELECT    dbo.sales.UnitPrice FROM dbo.sales INNER JOIN dbo.customer ON dbo.sales.CustomerCode = dbo.customer.CustomerCode  WHERE     dbo.customer.CustomerName =???? ?  ORDER BY dbo.sales.Invoice DESC", connection)

            Dim table As New DataTable()
            adapter.Fill(table)

    Hi,

    What do you want is the following data? Does not seem to need to use INNER JOIN .

    Dim adapter as New SqlDataAdapter("Select top 1 dbo.sales.UnitPrice From dbo.sales WHERE dbo.customer.CustomerName=Anzar order by pk-Sid desc", connection)

    Best Regards,

    Alex


    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.

    Friday, January 18, 2019 5:41 AM
  • hi

    i think in your code you make a store procedure.  now i want to take the value of @id from vb.net text box.  i use the vb.net  2010.



    MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

    The first screenshot is in Visual Studio which is what you were asking. The SQL is a representation of the first screenshot using a TableAdapter. Once you have created the query in the designer you would then have a .Fill method to pass in the id which in turn returns a populated data set if data was found for the id or an empty data set if no matching records.

    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, January 18, 2019 9:57 AM
    Moderator
  • i need unit price problem not solve what happen when date change

    MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

    Wednesday, January 23, 2019 6:31 PM
  • i need unit price problem not solve what happen when date change

    MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

    Can you point in the image below from your original question were there is anything indicating :what happen when date change"??? Also you never mentioned anything about a date here.


    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

    Thursday, January 24, 2019 1:37 AM
    Moderator
  • Just checking in to see how this is going (which is the same as the last post I replied too)?

    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

    Thursday, January 24, 2019 11:12 AM
    Moderator