المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Problem with the DataGrid Control



C# Programming
01-07-2010, 07:00 PM
Hello

I´m using an excellent tutorial:

http://www.codeproject.com/KB/grid/usingdatagrid.aspx

I'm not using MS Access, what is recommended in the tutorial, but MS SQL Comapact Edition as Data Provider. This shoult doesn't make a different.
But every time I try to execute the following code, an error message appear.
And the dataGrid is not displayed on the form.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;

namespace DataGridViewTest
{
public partial class Form1 : Form
{
private System.Windows.Forms.DataGrid dataGrid1; // definieren des neuen DataGrids

public Form1()
{
InitializeComponent();

// Define first a DataGrid and declare a new DataGrid, and then set some properties of the DataGrid (********, name, size etc..).
this.dataGrid1 = new System.Windows.Forms.DataGrid(); // deklarieren des DataGrids
this.dataGrid1.******** = new System.Drawing.Point(20, 20); // positionieren des DataGrids
this.dataGrid1.Name = "dataGrid1"; // DataGrid mit einem Namen Versehen
this.dataGrid1.Size = new System.Drawing.Size(200, 100); // Gr?sses des DataGrids angeben
}

// Now we can put all the commands needed into a method "fnDisplayDataInDataGrid()", to display data in the DataGrid.
private void fnDisplayDataInDataGrid()
{
// Verbindung zur Datenbank herstellen
string conStr = "Data Source=C:\\CSharp\\DataGridViewTest\\DB_Personen.sdf";
SqlCeConnection conn = new SqlCeConnection(conStr);

conn.Open(); // Verbindung zur Datenbank ?ffnen

SqlCeDataAdapter adapter = new SqlCeDataAdapter("SELECT * FROM Adressen", conn); // Erstellen des DataAdapter Objekts
DataSet ds = new DataSet(); // Erstellen des DataSet Objekts
adapter.Fill(ds, "Adresse"); // Tabelle "Adresse" in DataAdapter laden

this.dataGrid1.DataSource = ds.DefaultViewManager; // Anzeigen der Daten im DataGrid
// alternativ würde auch folgendes funktionieren:
// this.dataGrid1.SetDataBinding(ds,"Adresse");
}

private void Form1_Load(object sender, EventArgs e)
{
fnDisplayDataInDataGrid();
}
}
}


The error message predicate I need a DLL. But wich DLL and where can I get it ?

A first chance exception of type 'System.DllNotFoundException' occurred in System.Data.SqlServerCe.dll

Can someone help me, please ?

Sincere regards

Samuel