Reputation: 2551
I am new to winforms. I am trying to call stored procedure and display into devexpress gridview control
Here is my code what I tried
//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();
}
}
Error:
GridControl1 Doesn't contain a definition of data bind
Upvotes: 0
Views: 2150
Reputation: 3858
The DataBind
method is specific to ASP.NET controls. In WinForms, everything is tracked by setting a control property. So, there is no need to use the DataBind
method.
Then, DataSet is not bindable object. It contains a collection of such object. They are DataTables. So, it's necessary to set the DataSource property to one of the DataSet tables. For example, gridControl1.DataSource = ds.Tables[0];
. Or, if you have named tables, gridControl1.DataSource = ds.Tables['myTableName'];
. Alternatively, you can use the GridControl DataMember property to specify the table name.
gridControl1.DataSource = ds;
gridControl1.DataMember = "myTableName";
Upvotes: 1