说一下具体的吧 到哪里了就出错了?
省得大家摸不着头绪。。。
string str="server=localhost;uid=sa;pwd=;database=login";
SqlConnection conn=new SqlConnection(str);
SqlCommand cm=new SqlCommand();
cm.Connection=conn;
cm.CommandText="select * from login";
DataSet dt= new DataSet();
System.Data.SqlClient.SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=cm;
conn.Open();
da.Fill(dt,"login");
conn.Close();
// this.dataGrid1.DataSource=dt.Tables[0];
this.dataGrid1.SetDataBinding(dt,"login");
DataGridTableStyle dataGridStyle = new DataGridTableStyle();
dataGridStyle.MappingName = dt.Tables[0].TableName; //映射到数据表样式的名称
//建立数据行样式DataGridTextBoxColumn类
DataGridTextBoxColumn NumColumn = new DataGridTextBoxColumn();
NumColumn.MappingName = "编号";
NumColumn.HeaderText = "编号";
NumColumn.Width = 1000;
dataGridStyle.GridColumnStyles.Add(NumColumn);
DataGridTextBoxColumn NameColumn = new DataGridTextBoxColumn();
NameColumn.MappingName = "姓名";
NameColumn.HeaderText = "姓名";
NameColumn.Width =1000;
dataGridStyle.GridColumnStyles.Add(NameColumn);
DataGridTextBoxColumn PasswordColumn = new DataGridTextBoxColumn();
PasswordColumn.MappingName = "密码";
PasswordColumn.HeaderText = "密码";
PasswordColumn.Width = 1000;
dataGridStyle.GridColumnStyles.Add(PasswordColumn);
this.dataGrid1.TableStyles.Clear();
dataGrid1.TableStyles.Add(dataGridStyle);
根本改变不了。现在里面什么也没有