Start New Discussion within our Software Development Community

Is it possible to call a sql view in 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"

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

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

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

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()
                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
End Sub
This article has been dead for over six months. Start a new discussion instead.