Is it possible to call a sql view in vb.net? I can call stored procs, but when I change the code to read a view it says that "request for procedure failed because it is a view object"

Recommended Answers

All 5 Replies

A view is like a table, so wouldn't you need to SELECT data from it ?

Hi
You can view your SQl Table in vb.net with the help of DataSet and DataView.

EXAMPLE:
Dim cn3 As SqlCeConnection = Nothing
cn3 = New SqlCeConnection("Data Source=\My Documents\Databasename.sdf; " + "Password=")
Try
If cn3.State = ConnectionState.Open Then
cn3.Close()
End If
cn3.Open()
Dim da3 As New SqlCeDataAdapter("SELECT * FROM TABLENAME", cn3) '
da3.Fill(ds, "TABLENAME")
cn3.Close()

Dim dv As New DataView
dv = ds.Tables("TABLENAME").DefaultView
DataGrid1.DataSource = dv
Catch sce As SqlCeException
MessageBox.Show(sce.Message)
End Try
cn3.Close()

use this following code :
this code needed 1 datagrid to show data.

in Module :
Imports System.Data
Imports System.Data.SqlClient

Module Koneksi
    Public conn As SqlConnection
    Public Function GetConnect()
              
        conn = New SqlConnection("server = YourServerName;database = YourDatabaseName;Trusted_Connection = yes")
        Return conn
    End Function
End Module

procedure to show data :

Private Sub Show_Data()
        Dim conn As SqlConnection
        Dim cmdStudent As New SqlCommand
        Dim daStudent As New SqlDataAdapter
        Dim dsStudent As New DataSet
        Dim dtStudent As New DataTable

        ' Binding Data from Table Student
        conn = GetConnect()
            Try
                cmdStudent = conn.CreateCommand
                cmdStudent.CommandText = "SELECT * FROM Student"
                daStudent.SelectCommand = cmdStudent
                daStudent.Fill(dsStudent, "Student")
                dgStudent.DataSource = dsStudent
                dgStudent.DataMember = "Student"
                dgStudent.ReadOnly = True
            Catch ex As Exception
                MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Connection Error !!")
        End Try  
End Sub

in form, in form load event or other event :

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Show_Data()
End Sub

how do select two columns from table and bind the data in data grid view control in vb.net using SQl query

use join on your sql query.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.