C#中怎么把一个SQL表中的多个列的数据,组合成一个变量,在dataGridView中显示?
1个回答
2013-08-01
展开全部
可以,我的思路是这样的,DataSet ds=new DataSet();OlebDataAdapter oledbdataadapter1=new OlebDataAdapter("select * from table",conn);oledbdataadapter1.fill(ds,"table");ArrayList data=new Arraylist();foreach(DataRow dr in ds.tables["table"].Rows){ data.Add((DateTime)(dr[0].Tostring()+dr[1].Tostring()+dr[2].Tostring()));}大体上是这样的,返回一个动态数组,然后再绑定到dataGridview中;好久不写有些代码可能不是太对,大体思路是这样的。
补充一个思路,By Willin Wang:用DataSet ds=new DataSet();OlebDataAdapter oledbdataadapter1=new OlebDataAdapter("select * from table",conn);oledbdataadapter1.fill(ds,"table");ArrayList data=new Arraylist();
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
data.add( rdr[0].ToString()+rdr[1].ToString()+rdr[2].ToString());
}}
补充一个思路,By Willin Wang:用DataSet ds=new DataSet();OlebDataAdapter oledbdataadapter1=new OlebDataAdapter("select * from table",conn);oledbdataadapter1.fill(ds,"table");ArrayList data=new Arraylist();
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
data.add( rdr[0].ToString()+rdr[1].ToString()+rdr[2].ToString());
}}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询