none
How do I use a SQL View in VS2017 RRS feed

  • Question

  • Hi,
     
    Where can I find some guidance on how I can retrieve data from an MS SQL database using a SQL view  as a datasource.
     
     Thanks,
     

    • Edited by J Stoic Thursday, January 25, 2018 8:47 AM
    Thursday, January 25, 2018 8:46 AM

All replies

  • Hello,

    What do you mean by "SQL view" ?


    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 25, 2018 10:08 AM
    Moderator
  • Stoic,

    I think it is seldom used in .Net. But using it, it is the same as for a SP and a datareader. 

    Returned is a resultset which can be accessed by .Net classes as datareader and DBdataadapter (which set it automatically to a DataTable).


    Success Cor


    • Edited by Cor Ligthert Thursday, January 25, 2018 10:39 AM
    Thursday, January 25, 2018 10:39 AM
  • https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?category=sqlserver

    SQL Server Views can be discussed at the above forum.

    Thursday, January 25, 2018 11:51 AM
  • https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?category=sqlserver

    SQL Server Views can be discussed at the above forum.

    When do you start reading whole questions instead of a single word. 

    use a SQL View. not make a SQL view

    Or don't you know again that a SQL view can be used in C#?

    Or more likely, you don't know what a SQL view is.


    Success Cor


    • Edited by Cor Ligthert Thursday, January 25, 2018 11:56 AM
    Thursday, January 25, 2018 11:55 AM
  • https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?category=sqlserver

    SQL Server Views can be discussed at the above forum.

    When do you start reading whole questions instead of a single word. 

    use a SQL View. not make a SQL view

    Or don't you know again that a SQL view can be used in C#?

    Or more likely, you don't know what a SQL view is.


    Success Cor


    You are a real piece of work with another one of your ignorant Donald Trump like posts with iit not being limited to your wild ignorance displayed in to the VB.NET forum and now following around like the clown that you are Unsuccess Cor. 
    Thursday, January 25, 2018 1:59 PM
  • https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?category=sqlserver

    SQL Server Views can be discussed at the above forum.

    When do you start reading whole questions instead of a single word. 

    use a SQL View. not make a SQL view

    Or don't you know again that a SQL view can be used in C#?

    Or more likely, you don't know what a SQL view is.


    Success Cor


    You are a real piece of work with another one of your ignorant Donald Trump like posts with iit not being limited to your wild ignorance displayed in to the VB.NET forum and now following around like the clown that you are Unsuccess Cor. 
    I want to know what in the h*** is wrong with you Cor?
    Thursday, January 25, 2018 2:04 PM
  • Typically you treat a VIEW the same way as a TABLE when querying data. Just specify the name in your data source.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, January 25, 2018 6:19 PM
  • Paul is exactly right.

    Here is an example based off the following code sample I recently wrote. I created the following view

    Wrote the code to get one field from the view

    Public Function CustomerView() As DataTable
        mHasException = False
        Dim dt As New DataTable
        Dim selectStatement As String = "SELECT LastName FROM CustomerLastNameView"
        Try
            Using cn = New SqlConnection(ConnectionString)
                Using cmd = New SqlCommand() With {.Connection = cn, .CommandText = selectStatement}
                    cmd.CommandText = selectStatement
                    cn.Open()
                    dt.Load(cmd.ExecuteReader)
                End Using
            End Using
        Catch ex As Exception
            mHasException = True
            mLastException = ex
        End Try
    
        Return dt
    
    End Function

    Wrote a test method to ensure it works (which it does of course)


    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 26, 2018 1:23 AM
    Moderator