自己建的一个DataTable怎样绑定到DataGrid ?
DataSet ds1 , ds2 ;
DataTable dt = new DataTable();
DataRow dr;
string strsel = "select Own_Server from Info_Own ";
dt.Columns.Add(new DataColumn( "服务器名称 ",typeof(string)));
for (int k = 0 ;k < 3 ; k++)
{
dt.Columns.Add(new DataColumn( "单价 "+k.ToString(),typeof(float)));
dt.Columns.Add(new DataColumn( "数量 "+k.ToString(),typeof(string)));
dt.Columns.Add(new DataColumn( "收购商 "+k.ToString(),typeof(string)));
}
ds1 = DB.ExecuteSqlDS(strsel, "temp ");
for(int i = 0; i <ds1.Tables[ "temp "].Rows.Count;i++)
{
dr = dt.NewRow();
dr[ "服务器名称 "] = ds1.Tables[ "temp "].Rows[i][0].ToString();
string strsec = "select top 3 价格,数量,收购商名称 from serverInfo where 服务器名称 = "+ " ' "+ds1.Tables[ "temp "].Rows[i][0].ToString()+ " ' "+ " ORDER BY 价格 desc ";
ds2 = DB.ExecuteSqlDS(strsec, "temp2 ");
for(int n = 0 ; n < ds2.Tables[ "temp2 "].Rows.Count ; n++)
{
dr[ "单价 "+n.ToString()] = ds2.Tables[ "temp2 "].Rows[n][ "价格 "];
dr[ "数量 "+n.ToString()] = ds2.Tables[ "temp2 "].Rows[n][ "数量 "];
dr[ "收购商 "+n.ToString()] = ds2.Tables[ "temp2 "].Rows[n][ "收购商名称 "];
}
}
this.imageShow.DataSource = dt;
dt中已经有了数据,但界面显示出来的时候没有数据....
------解决方案--------------------看的真晕.没发现dt.Rows.Add(dr)