GridControl(GridView)不返回任何行

时间:2012-03-23 14:44:45

标签: c# gridview devexpress gridcontrol

编辑:修正.. 我认为通过添加新项目修复了问题 - >持久化类11.2并通过向导添加新的持久化类。然后我只是复制了代码并将其放入我的Form1代码中。作品!

我非常密切关注此页面:http://documentation.devexpress.com/#WindowsForms/CustomDocument3265

我尝试了两种方法来获取网格控制设置以显示来自SQL Server数据库的记录,但都没有工作。两者(当我运行程序时)返回列但没有行。我很肯定我有正确的SQL服务器名称,数据库名称和表名。搜索谷歌似乎返回“如何让程序显示一条消息,说'找不到行'',即没有用。这是我的代码:

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 DevExpress.Xpo;
using DevExpress.Xpo.DB;
using DevExpress.Xpo.Metadata;
using DevExpress.XtraGrid;

namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        // Generate the connection string to the AdventureWorks database on local SQL Server. 
        XpoDefault.ConnectionString = 
          MSSqlConnectionProvider.GetConnectionString("dsd-sql3", "PH");
        // Create a Session object. 

        Session session1 = new Session(XpoDefault.GetDataLayer(XpoDefault.ConnectionString, AutoCreateOption.None));
        // Create an XPClassInfo object corresponding to the Person_Contact class. 
        XPClassInfo classInfo = session1.GetClassInfo(typeof(Call));
        // Create an XPServerCollectionSource object. 
        XPServerCollectionSource xpServerCollectionSource1 = 
          new XPServerCollectionSource(session1, classInfo);
        xpServerCollectionSource1.Reload();
        // Create a grid control. 
        GridControl gridControl1 = new GridControl();
        gridControl1.Dock = DockStyle.Fill;
        this.Controls.Add(gridControl1);
        // Enable server mode. 
        gridControl1.ServerMode = true;
        // Bind the grid control to the data source. 
        gridControl1.DataSource = xpServerCollectionSource1;
    }
}

[Persistent("dbo.CallLog")]
public class Call : XPLiteObject 
{
    public Call(Session session) : base(session) { }
    [Key, DevExpress.Xpo.DisplayName("Oid")]
    public string Oid;
    //public string Title;
    [DevExpress.Xpo.DisplayName("FirstName")]
    public string FirstName;
    [DevExpress.Xpo.DisplayName("MiddleName")]
    public string MiddleName;
    [DevExpress.Xpo.DisplayName("LastName")]
    public string LastName;
    [DevExpress.Xpo.DisplayName("Email")]
    public string Email;
    //public string Phone;
}

}

我的同事说可能数据是从数据库加载但没有链接,他不知道如何解决它......

非常感谢任何帮助。感谢。

0 个答案:

没有答案