日期:2014-05-18  浏览次数:20830 次

请问我以下代码的dataGrid为什么没数据啊,数据库里有数据。
请问我以下代码的dataGrid为什么没数据啊,数据库里有数据。
保存后刷新dataGrid,是设置dataGridList.DataSource=ds.Table[0];
怎么使绑定的DataSet中的表更新啊。

private void BindingControl()
{
//-----------------------Binding List------------------------------
  tBoxVisit.DataBindings.Add("Text",Ds,"tbCustVisit.cvId");
  ......
  dataGridList.SetDataBinding(Ds, "tbCustVist");
  dataGridItemList.SetDataBinding(Ds,"tbCustVisitItem");
  dataGridColorList.SetDataBinding(Ds,"tbCustvisitItemColor");
}

private void initControl()
{
connect = new SqlConnection(ComString.ConnectS);
Ds = new DataSet();
   
DaList = new SqlDataAdapter(sqltextList, connect);
cbList = new SqlCommandBuilder(DaList);
DaList.Fill(Ds, "tbCustVisit");

DaItemList = new SqlDataAdapter(sqltextItemList, connect);
cbItemList = new SqlCommandBuilder(DaItemList);
DaItemList.Fill(Ds, "tbCustVisitItem");

DaColorList = new SqlDataAdapter(sqltextColorList, connect);
cbColorList = new SqlCommandBuilder(DaColorList);
DaColorList.Fill(Ds, "tbCustvisitItemColor");

//-----------------------Add Relation---------------------------
 
DataColumn Dc1=Ds.Tables["tbCustVisit"].Columns["cvId"];
DataColumn Dc2=Ds.Tables["tbCustVisitItem"].Columns["cvId"];

DataRelation Dr1 = new DataRelation("ListToItem", Dc1, Dc2);

Ds.Relations.Add(Dr1);

//-----------------------Add Relation---------------------------

DataColumn[] Dc3 = new DataColumn[2];
DataColumn[] Dc4 = new DataColumn[2];

Dc3[0]=Ds.Tables["tbCustVisitItem"].Columns["cvId"];
Dc3[1]=Ds.Tables["tbCustVisitItem"].Columns["mlId"];

Dc4[0]=Ds.Tables["tbCustvisitItemColor"].Columns["cvId"];
Dc4[1]=Ds.Tables["tbCustvisitItemColor"].Columns["mlId"];

DataRelation Dr2 = new DataRelation("ItemToCorlor", Dc3, Dc4);

Ds.Relations.Add(Dr2);
}



------解决方案--------------------
给完数据源后绑定了吗
.DataBind() 方法
------解决方案--------------------
你断点看看数据集里有数据吗?
------解决方案--------------------
dataGridColorList.DataBind()
------解决方案--------------------
你没帮定