为什么datagrid无法显示数据?急
private void ecomponent_Load(object sender, System.EventArgs e)
{ //MyConn=new SqlConnection()
DataSet FacNumset=new DataSet();
MyConn.Open();//打开连接
FacNumAdapter.SelectCommand.CommandText = "SELECT * FROM ecomponent";
FacNumAdapter.SelectCommand.Connection = MyConn;
FacNumAdapter.Fill(FacNumInfo);//填充数据表
this.dataGrid1.DataSource = FacNumInfo.DefaultView;
FNReport = (CurrencyManager) BindingContext[FacNumInfo];
DataGridTableStyle fn = new DataGridTableStyle();
this.DataBindingsFunction();
fn.AlternatingBackColor = Color.Blue;//颜色设置
fn.MappingName = FacNumInfo.TableName;
this.dataGrid1.Select(0);//选定第一列
}
private void DataBindingsFunction()//绑定
{
this.textNum.DataBindings.Add("Text",FacNumInfo,"元器件编号");
this.textName.DataBindings.Add("Text",FacNumInfo,"元器件名称");
this.textBox1.DataBindings.Add("Text",FacNumInfo,"规格");
this.textBox2.DataBindings.Add("Text",FacNumInfo,"单位");
this.textBox3.DataBindings.Add("Text",FacNumInfo, "产地");
this.textBox4.DataBindings.Add("Text",FacNumInfo, "备注");
} --------------------编程问答-------------------- 楼主,看一下你的结贴率,估计都没人回答你的问题.. --------------------编程问答-------------------- 在调用方法之后写这句话试一下,不行再找我吧。。。
this.FacNumInfo.DataSource = FacNumset.Tables[0];
不过我建议你用datagridview控件试一下。也可以实现你的要求。
补充:.NET技术 , C#