S
Skandy
Hello:
This must be quite simple! But I couldnt figure out whats wrong:
I have this following code, and I still see a blank datagrid:
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim conn As New SqlConnection("****")
Dim da As New SqlDataAdapter("Select * from tblNote where CDID
= 55", conn)
Dim ds As New DataSet
Dim dt As New DataTable
da.Fill(ds)
If (ds.Tables(0).Rows.Count > 100) Then
dt = Get100Rows(ds.Tables(0))
End If
dt.AcceptChanges()
Dim dv As New DataView(dt)
Try
DataGridView1.DataSource = dv
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Function Get100Rows(ByRef dt As DataTable) As DataTable
Dim dt1 As New DataTable
Dim i As Integer
For i = 0 To 99
dt1.ImportRow(dt.Rows(i))
Next
dt1.AcceptChanges()
Get100Rows = dt1
End Function
End Class
I can see that the DataTable dt has 1000 rows. The datagrid does get
populated if I were to have Tables(0) of the DataSet ds as the
DataSource.
TIA.
Skandy
This must be quite simple! But I couldnt figure out whats wrong:
I have this following code, and I still see a blank datagrid:
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim conn As New SqlConnection("****")
Dim da As New SqlDataAdapter("Select * from tblNote where CDID
= 55", conn)
Dim ds As New DataSet
Dim dt As New DataTable
da.Fill(ds)
If (ds.Tables(0).Rows.Count > 100) Then
dt = Get100Rows(ds.Tables(0))
End If
dt.AcceptChanges()
Dim dv As New DataView(dt)
Try
DataGridView1.DataSource = dv
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Function Get100Rows(ByRef dt As DataTable) As DataTable
Dim dt1 As New DataTable
Dim i As Integer
For i = 0 To 99
dt1.ImportRow(dt.Rows(i))
Next
dt1.AcceptChanges()
Get100Rows = dt1
End Function
End Class
I can see that the DataTable dt has 1000 rows. The datagrid does get
populated if I were to have Tables(0) of the DataSet ds as the
DataSource.
TIA.
Skandy