可以, 动态列的名字默认是field name.
MSDN中的sample:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;public class DataGridSample:Form{
   DataSet ds;
   DataGrid myGrid;   static void Main(){
      Application.Run(new DataGridSample());
   }   public DataGridSample(){
      InitializeComponent();
   }   void InitializeComponent(){
      this.ClientSize = new System.Drawing.Size(550, 450);
      myGrid = new DataGrid();
      myGrid.Location = new Point (10,10);
      myGrid.Size = new Size(500, 400);
      myGrid.CaptionText = "Microsoft .NET DataGrid";
      this.Text = "C# Grid Example";
      this.Controls.Add(myGrid);
      ConnectToData();
      myGrid.SetDataBinding(ds, "Suppliers");
   }
   void ConnectToData(){
      // Create the ConnectionString and crete a SqlConnection.
      // Change the data source value to the name of your computer.
      
      string cString = "user id=sa;" + 
      "password=;" + 
      "initial catalog=northwind;" + 
      "data source=MyComputerName\\NetSDK;" +
      "Connect Timeout=5";
      SqlConnection myConnection = new SqlConnection(cString);
      // Create a SqlDataAdapter.
      SqlDataAdapter myAdapter = new SqlDataAdapter();
      myAdapter.TableMappings.Add("Table", "Suppliers");
      myConnection.Open();
      SqlCommand myCommand = new SqlCommand("SELECT * FROM Suppliers",
      myConnection);
      myCommand.CommandType = CommandType.Text;
   
      myAdapter.SelectCommand = myCommand;
      Console.WriteLine("The connection is open");
      ds = new DataSet("Customers");
      myAdapter.Fill(ds);
      // Create a second Adapter and Command.
      SqlDataAdapter adpProducts = new SqlDataAdapter();
      adpProducts.TableMappings.Add("Table", "Products");
      SqlCommand cmdProducts = new SqlCommand("SELECT * FROM Products", 
      myConnection);
      adpProducts.SelectCommand = cmdProducts;
      adpProducts.Fill(ds);
      myConnection.Close();
      Console.WriteLine("The connection is closed.");
      System.Data.DataRelation dr;
      System.Data.DataColumn dc1;
      System.Data.DataColumn dc2;
      // Get the parent and child columns of the two tables.
      dc1 = ds.Tables["Suppliers"].Columns["SupplierID"];
      dc2 = ds.Tables["Products"].Columns["SupplierID"];
      dr = new System.Data.DataRelation("suppliers2products", dc1, dc2);
      ds.Relations.Add(dr);
   }
}

解决方案 »

  1.   

    Hi Girlvia,感谢您使用微软产品!在默认情况下,DataGrid显示的列名就是你SQL语句中所选择字段的字段名。不过,你也可以用在所选的字段后面加上"as" 关键字来指定一个新名字,比如:Select nID as "Employee ID" from .....这样显示的不再是"nID",而是"Employee ID"。-微软全球技术中心 VC技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
    为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。