|
-
Jan 13th, 2006, 03:45 PM
#1
Thread Starter
Lively Member
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.
-
Jan 13th, 2006, 04:10 PM
#2
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?
-
Jan 13th, 2006, 04:22 PM
#3
Thread Starter
Lively Member
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
-
Jan 13th, 2006, 04:36 PM
#4
Re: Any Detailed Source on Dataviews?
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConn As String = "server=;Database=Northwind;user=;Password="
Dim sqlConn As New SqlClient.SqlConnection(strConn)
Dim strSQL As String = "SELECT * FROM Employees"
Dim sqlCmd As New SqlClient.SqlCommand(strSQL, sqlConn)
Dim adap As New SqlClient.SqlDataAdapter(sqlCmd)
Dim ds As New DataSet
Try
'Query Northwind Employees
sqlConn.Open()
adap.Fill(ds, "Employees")
Me.DataView1 = ds.Tables(0).DefaultView
Me.Label1.text = DataView1.Count
Catch ex As Exception
Finally
If sqlConn.State = ConnectionState.Open Then
sqlConn.Close()
End If
sqlConn.Dispose()
sqlCmd.Dispose()
adap.Dispose()
End Try
End Sub
-
Jan 13th, 2006, 04:42 PM
#5
Thread Starter
Lively Member
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?
-
Jan 13th, 2006, 04:48 PM
#6
Re: Any Detailed Source on Dataviews?
No, but you can do this:
VB Code:
Private WithEvents dt As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConn As String = "server=;Database=Northwind;user=;Password="
Dim sqlConn As New SqlClient.SqlConnection(strConn)
Dim strSQL As String = "SELECT * FROM Employees"
Dim sqlCmd As New SqlClient.SqlCommand(strSQL, sqlConn)
Dim adap As New SqlClient.SqlDataAdapter(sqlCmd)
Try
'Query Northwind Employees
sqlConn.Open()
adap.Fill(dt)
Me.DataView1 = dt.DefaultView
Me.Label1.Text = Me.DataView1.Count 'set the initial
Catch ex As Exception
Finally
If sqlConn.State = ConnectionState.Open Then
sqlConn.Close()
End If
sqlConn.Dispose()
sqlCmd.Dispose()
adap.Dispose()
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.DataView1.AddNew()
End Sub
Private Sub DataView1_ListChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs) Handles DataView1.ListChanged
Me.Label1.Text = Me.DataView1.Count 'refresh count
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.
-
Jan 13th, 2006, 05:09 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|