编辑:已修复..我相信通过添加新项目 - > 持久类 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;
}
}
我的同事说数据可能是从数据库加载但没有链接,他不知道如何修复它......
任何帮助是极大的赞赏。谢谢。