【发布时间】:2018-01-17 20:07:22
【问题描述】:
我是winforms的新手。我正在尝试调用存储过程并显示到 devexpress gridview 控件中
这是我尝试过的代码
//Header file
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public Form3()
{
InitializeComponent();
//string cs = Properties.Settings.TestDatabaseConnectionString;
var connectionString = ConfigurationManager.ConnectionStrings["TestDatabaseConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = connectionString;
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "ReportStudentDetails";
cmd.Connection = con;
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
gridControl1.DataSource = ds;
gridControl1.DataBind(); // showing error
con.Close();
}
}
错误:
GridControl1 不包含数据绑定的定义
【问题讨论】:
-
删除
gridControl1.DataBind();行。gridControl1.DataSource = ds;就足够了。 -
另外,ASP.NET 和 WinForms 是不兼容的技术。你是如何一起使用它们的?
-
@Gosha_Fighten 正如你提到的,我删除了。现在没有错误。但同时它没有显示任何记录
-
将网格数据源设置为您的 DataSet 所需的表。例如:
gridControl1.DataSource = ds.Tables[0]; -
@Gosha_Fighten Bro 你是对的,你能否详细解释一下你的答案,这对其他人也会更有帮助
标签: c# asp.net winforms gridview devexpress