示例#1
0
        /// <summary>
        /// Set the data from the specified table into the data grid.
        /// Show the table's scheme if showSchema is true.
        /// </summary>
        /// <param name="miTable"></param>
        /// <param name="showSchema"></param>
        private void SetGrid(MapInfo.Data.Table miTable, bool showSchema)
        {
            dataGrid.CaptionText       = miTable.Alias;
            this.miCommand.CommandText = "Select * from " + miTable.Alias;
            MapInfo.Data.MIDataReader miReader = this.miCommand.ExecuteReader();
            DataTable dt = new DataTable("Data");

            for (int i = 0; i < miReader.FieldCount; i++)
            {
                DataColumn dc = dt.Columns.Add(miReader.GetName(i));
            }
            while (miReader.Read())
            {
                DataRow dr = dt.NewRow();
                for (int i = 0; i < miReader.FieldCount; i++)
                {
                    dr[i] = miReader.GetValue(i);
                }
                dt.Rows.Add(dr);
            }
            if (showSchema)
            {
                dataGrid.DataSource = miReader.GetSchemaTable();
            }
            else
            {
                dataGrid.DataSource = dt;
            }
            miReader.Close();
        }
示例#2
0
 private void SetDataGrid(DataGrid dataGrid, string commandText, bool bShowSchema)
 {
     MapInfo.Data.MIConnection miConnection = new MIConnection();
     miConnection.Open();
     MapInfo.Data.MICommand miCommand = miConnection.CreateCommand();
     miCommand.CommandText = commandText;
     MapInfo.Data.MIDataReader miReader = null;
     try
     {
         miReader = miCommand.ExecuteReader();
         if (bShowSchema)
         {
             dataGrid.DataSource = miReader.GetSchemaTable();
         }
         else
         {
             DataTable dt = new DataTable("Data");
             for (int index = 0; index < miReader.FieldCount; index++)
             {
                 DataColumn dc = dt.Columns.Add(miReader.GetName(index));
             }
             while (miReader.Read())
             {
                 DataRow dr = dt.NewRow();
                 for (int index = 0; index < miReader.FieldCount; index++)
                 {
                     dr[index] = miReader.GetValue(index);
                 }
                 dt.Rows.Add(dr);
             }
             dataGrid.DataSource = dt;
         }
     }
     catch (Exception)
     {
         SelectClauseTextBox.Text += " ***Wrong select clause, try it.***";
     }
     finally
     {
         if (miReader != null)
         {
             miReader.Close();
         }
     }
 }