Data grid

G

Guest

Hello,

I want to display my data in a datagrid, i am bringing this data from the db
using a sqlCeDataReader. Now, after i have my sqlCeDataReader how to display
it in the datagrid?

Thank you
 
W

William Ryan eMVP

It's too much trouble.. I'd use a SqlCeDataAdapter and then fill a DataTable
object, then just bind the grid to it. If you *must* use a SqlCeDataReader,
then you'll have to fill some sort of dataobject and/or strongly typed
collection and bind to it.

If you use a DataTable, you'll just need to set the datasource property
(probably want to call Application.DoEvents() as well b/c PPC screens don't
always refresh well).
 
C

Cor Ligthert

Philip,

Although I agree with the answer from Bill

Do I give you this sample that I once made. It is a fill from a datatable
with a progressbar. It was often asked. And than when my sample was ready,
it was not asked anymore.

However your question is in it, so I am glad that I can show it.

\\\Needs a progressbar, a button and a datagrid
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New SqlClient.SqlConnection("Server=MyServer;" & _
"DataBase=Northwind; Integrated Security=SSPI")
Dim cmd As New SqlClient.SqlCommand("Select Count(*) from
Employees", conn)
conn.Open()
ProgressBar1.Maximum = DirectCast(cmd.ExecuteScalar, Integer)
ProgressBar1.Step = 1
ProgressBar1.Minimum = 0
cmd.CommandText = "SELECT * FROM Employees"
Dim rdr As SqlClient.SqlDataReader = cmd.ExecuteReader()
Dim dt As DataTable
While rdr.Read
If dt Is Nothing Then
dt = New DataTable
Dim dtschema As DataTable
dtschema = rdr.GetSchemaTable
For Each drschema As DataRow In dtschema.Rows
dt.Columns.Add(drschema("ColumnName").ToString, _
Type.GetType(drschema("DataType").ToString))
Next
End If
ProgressBar1.PerformStep()
Dim dr As DataRow = dt.NewRow
Dim tempObject(dt.Columns.Count - 1) As Object
rdr.GetValues(tempObject) 'did not go in one time
dr.ItemArray = tempObject
dt.Rows.Add(dr)
Threading.Thread.Sleep(500) 'only for showing
End While
DataGrid1.DataSource = dt
rdr.Close()
conn.Dispose()
End Sub
///

I hope this helps a little bit?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top