this.sqlConnection1.Open();
this.dreader = this.sqlCommand3.ExecuteReader();
this.DataGrid1.DataSource = dreader;
this.DataGrid1.DataBind();
this.dreader.Close();
this.sqlConnection1.Close();How do I Bind Data to a Datagrid in a C# Windows Application?
I'm editing my response first, because actually you are correct--the DataBind() method doesn't exist for a Windows control. You would use the control.DataBindings.Add() method.
Assuming you have a DataGrid called ';MyGrid';, and you already have your sqlConnection1 SqlConnection object:
SqlDataAdapter objDA = null;
DataSet objDS = null;
objDA = new SqlDataAdapter(SQL, objConn.Conn);
objDS = new DataSet();
objDA.Fill(objDS);
MyGrid.DataSource = objDS.Tables[0];
No comments:
Post a Comment