SqlConnection conn = new SqlConnection ( "server = (local); Database = prjmaster; uid = sa; pwd = 123456"); SqlDataAdapter da = new SqlDataAdapter ( "SELECT TOP 10 * FROM Bug", conn); DataSet ds = new DataSet (); Try {Da.Fill (DS, "BugTable");} catch (exception ex) {messagebox.show (ex.Message);} DataGrid1.datasource = DS.TABLES ["BugTable"];
CurrencyManager mycurrencymanger = // Gets the target list manager this.bindingContext [DS];
DataGridtableStyle myTableStyle = new dataGridtableStyle (); // Create a table style mytablestyle.mappingname = "bugTable";
PropertyDescriptor myDateDescriptor = // Get PropertyDescriptor myCurrencyManger.GetItemProperties column contains the date () [ "bugopendate"]; // 'G' is for MM / dd / yyyy HH:. Mm: ss date format DataGridColumnStyle myDateStyle = // create a column Style New DataGridTextBoxColumn (MyDatedScriptor, "G");
MyDateStyle.mappingName = "bugopendate"; // column name mydatestyle.Headertext = "bug open date" in the database; // To display text mydatestyle.Width = 150 on the DataGird header; // Width
/ * If you want to display multiple columns, it is necessary to generate more DataGridColumnStyle objects * / DataGridColumnStyle column2 = new DataGridTextBoxColumn (); column2.MappingName = "bugassignto"; column2.HeaderText = "Bug recipients";
MyTableStyle.GridColumnStyles.Add (MyDateStyle); // Add column style myTableStyle.GridColumnStyles.Add (Column2);
DataGrid1.tables.add (myTableStyle); // Add a table style to DataGrid