DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   sql view in vb.net (http://www.daniweb.com/forums/thread110163.html)

Pareshja Feb 21st, 2008 9:45 am
sql view in vb.net
 
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"

ads248 Feb 21st, 2008 10:17 am
Re: sql view in vb.net
 
A view is like a table, so wouldn't you need to SELECT data from it ?

suganzeni Mar 4th, 2008 12:49 am
Re: sql view in vb.net
 
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()

Jx_Man Mar 4th, 2008 11:40 pm
Re: sql view in vb.net
 
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

gomathinayagam Nov 29th, 2008 1:31 am
Re: sql view in vb.net
 
how do select two columns from table and bind the data in data grid view control in vb.net using SQl query

Jx_Man Nov 30th, 2008 2:35 pm
Re: sql view in vb.net
 
use join on your sql query.


All times are GMT -4. The time now is 12:48 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC