SQL Server CE DataGrid

  • Thread starter Gabrielle Shegog via .NET 247
  • Start date
G

Gabrielle Shegog via .NET 247

For some reason I cannot populate my datagrid. Here is the code:

Dim cString As String
cString = "Data Source = ACServe.sdf"
Dim cn As System.Data.SqlServerCe.SqlCeConnection
Dim SQL As String
Dim SQLEngine As System.Data.SqlServerCe.SqlCeEngine

If Not System.IO.File.Exists("ACServe.sdf") Then
SQLEngine = New System.Data.SqlServerCe.SqlCeEngine _
("data source=ACServe.sdf")
SQLEngine.CreateDatabase()
End If

cn = New System.Data.SqlServerCe.SqlCeConnection("Data Source=ACServe.sdf")
cn.Open()

ds = New DataSet

Dim adpCallout As SqlCeDataAdapter = New SqlCeDataAdapter("select * from Callout", cn)
Dim tbl As DataTable

tbl = New DataTable("Callout")
adpCallout.Fill(tbl)
dgJobList.DataSource = tbl

Please help!!!
 
D

Darren Shaffer

Have you defined a data grid style that matches the columns of your
Callout table? If you're not getting a SqlCe exception and
you just aren't seeing any rows in your grid when this code completes,
it's likely your grid doesn't know how to handle the data table you are
assigning as the datasource. Example (call this before you set the
datagrid's datasource):

private void _assignGridStyle()
{
DataGridTableStyle ts1 = new DataGridTableStyle();
DataGridTextBoxColumn mycol = new DataGridTextBoxColumn();

mycol.MappingName = "Name";
mycol.HeaderText = "Name";
mycol.Width = 50;
ts1.GridColumnStyles.Add(mycol);

mycol = new DataGridTextBoxColumn();
mycol.MappingName = "Addr";
mycol.HeaderText = "Addr";
mycol.Width = 50;
ts1.GridColumnStyles.Add(mycol);

mycol = new DataGridTextBoxColumn();
mycol.MappingName = "City";
mycol.HeaderText = "City";
mycol.Width = 50;
ts1.GridColumnStyles.Add(mycol);

mycol = new DataGridTextBoxColumn();
mycol.MappingName = "State";
mycol.HeaderText = "State";
mycol.Width = 10;
ts1.GridColumnStyles.Add(mycol);

mycol = new DataGridTextBoxColumn();
mycol.MappingName = "Zip";
mycol.HeaderText = "Zip";
mycol.Width = 25;
ts1.GridColumnStyles.Add(mycol);

dgJobList.TableStyles.Add(ts1);
}

--
Darren Shaffer
..NET Compact Framework MVP
Principal Architect
Connected Innovation
www.connectedinnovation.com
 

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