Results 1 to 7 of 7

Thread: Any Detailed Source on Dataviews?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    90

    Exclamation Any Detailed Source on Dataviews?

    I've searched all over th web on information on dataviews as well as bought 4 books which only breifly describe what a dataview is. I need a source that will allow me to get into the guts of dataviews. Does anyone know where I could find such info? Book? URL?

    I have a project that requires that I be able to run a query on a Dataview or datatable and be able to count the rows.

  2. #2
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: Any Detailed Source on Dataviews?

    There's a member of DataView (DataView1.Count) that gives you the number of items.

    Are you asking for something a little more specific? Can you give a more specified example of when you want to find out how many rows there are? Are you talking about finding out the number of rows effected when you run commands against DataViews and DataTables?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    90

    Re: Any Detailed Source on Dataviews?

    Well, I could get by if I could bind a label to the dataview.count property. Is that possible? A sample would be deeply appreciated.

    Dan

  4. #4
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: Any Detailed Source on Dataviews?

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim strConn As String = "server=;Database=Northwind;user=;Password="
    3.         Dim sqlConn As New SqlClient.SqlConnection(strConn)
    4.         Dim strSQL As String = "SELECT * FROM Employees"
    5.         Dim sqlCmd As New SqlClient.SqlCommand(strSQL, sqlConn)
    6.  
    7.         Dim adap As New SqlClient.SqlDataAdapter(sqlCmd)
    8.         Dim ds As New DataSet
    9.  
    10.         Try
    11.             'Query Northwind Employees
    12.             sqlConn.Open()
    13.             adap.Fill(ds, "Employees")
    14.             Me.DataView1 = ds.Tables(0).DefaultView
    15.             Me.Label1.text = DataView1.Count
    16.         Catch ex As Exception
    17.  
    18.         Finally
    19.             If sqlConn.State = ConnectionState.Open Then
    20.                 sqlConn.Close()
    21.             End If
    22.             sqlConn.Dispose()
    23.             sqlCmd.Dispose()
    24.             adap.Dispose()
    25.         End Try
    26.     End Sub

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    90

    Re: Any Detailed Source on Dataviews?

    thanks but I need to actually bind the DatView.count to the label because I'm going to be updating the datatable every minute. Will the code above reflect the updated datatable as well?

  6. #6
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: Any Detailed Source on Dataviews?

    No, but you can do this:
    VB Code:
    1. Private WithEvents dt As New DataTable
    2.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.         Dim strConn As String = "server=;Database=Northwind;user=;Password="
    4.         Dim sqlConn As New SqlClient.SqlConnection(strConn)
    5.         Dim strSQL As String = "SELECT * FROM Employees"
    6.         Dim sqlCmd As New SqlClient.SqlCommand(strSQL, sqlConn)
    7.  
    8.         Dim adap As New SqlClient.SqlDataAdapter(sqlCmd)
    9.  
    10.         Try
    11.             'Query Northwind Employees
    12.             sqlConn.Open()
    13.             adap.Fill(dt)
    14.             Me.DataView1 = dt.DefaultView
    15.             Me.Label1.Text = Me.DataView1.Count  'set the initial
    16.         Catch ex As Exception
    17.  
    18.         Finally
    19.             If sqlConn.State = ConnectionState.Open Then
    20.                 sqlConn.Close()
    21.             End If
    22.             sqlConn.Dispose()
    23.             sqlCmd.Dispose()
    24.             adap.Dispose()
    25.         End Try
    26.     End Sub
    27.  
    28.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    29.         Me.DataView1.AddNew()
    30.     End Sub
    31.  
    32.     Private Sub DataView1_ListChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs) Handles DataView1.ListChanged
    33.         Me.Label1.Text = Me.DataView1.Count 'refresh count
    34.     End Sub
    There is no "binding a label" to a dataview or datatable. You can associate events though.

    **EDIT**
    Changed the events (they were raising in a different order then I thought. This should work now that I tested it.)
    Last edited by sevenhalo; Jan 13th, 2006 at 05:07 PM.

  7. #7
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: Any Detailed Source on Dataviews?

    Bump

    (Made a change to the example, need to grab your attention.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width