如何把多表连接的数据集结果,手动绑定到gridview,十万火急! 如题,谢谢,急 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 直接绑定不行吗、?gridview.datasource=(集合或者table)gridview.databind(); 有代码么?参考一下谢谢了sql查询语句:select a.col1,b.col1 from table1 a,table2 b where a.serialno = b.serialno; select a.*,b.* from a,b或union select a.col1 as name,b.col1 as name from table1 a,table2 b where a.serialno = b.serialno;<%#Eval("name")%> OdbcConnection myCon = new OdbcConnection(WebConfigurationManager.ConnectionStrings["stringcon"].ToString()); myCon.Open(); try { string str_sql = ""; str_sql = sqltext; OdbcDataAdapter myData = new OdbcDataAdapter(str_sql, myCon); DataSet MyDs = new DataSet(); myData.Fill(MyDs, "customerinfor"); GridView1.DataSource = MyDs.Tables["customerinfor"].DefaultView; GridView1.DataKeyNames = new string[] { "customerno" }; GridView1.DataBind(); } catch (Exception p) { } finally { myCon.Close(); }一个表,我是这样写的,两个表话myData.Fill(MyDs, "customerinfor");能这样写么? 直接写一个视图也可以啊。写了个查询返回一个集合的方法将此方法作为数据源绑定到GridView的DataSource中咯。gridview.datasource=(集合或者table)gridview.databind(); 用这种public DataTable GetDate(string where) { SqlConnection cn = new SqlConnection(); cn.ConnectionString = ""; SqlCommand cmd = new SqlCommand(); DataTable dt = new DataTable(); SqlDataReader dr = null; cmd.CommandText = where; cmd.Connection = cn; using (dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { dt.Load(dr); } if (dt.Rows.Count != 0) { return dt; } else { return null; } }返回一个DataTable 然后this.GridView1.DataSource =GetDate;GridView1.DataBind();多张表查询可以SQL的 连接 left join or right join or inner join 然后弄好SQL传入到方法里就行了。 ASP。NET连接DB2 非常急的问题!!!!!!各位兄弟姐妹救急啊 ASP.NET(C#)如何判断texbox中的内容? AjaxPro 调用后台报错了该怎么做啊 JS循环验证附件格式 请多指教 想问一下OA系统的版式问题。 怎样取得SQL SERVER中的 时间戳 数据? 一个简单的问题,通过 URL 或 get 方式发送数据,长度有限制吗? 大家情帮忙,我问个asp和aspx的整合问题?? 菜鸟请教(急急急,在线等。。。) asp。net 按条件查询 vs2005 asp.net 发布后 Global.asax 失效|不运行如何代理 , 如何处理? Grid++Report
gridview.datasource=(集合或者table)
gridview.databind();
参考一下
谢谢了
sql查询语句:
select a.col1,b.col1 from table1 a,table2 b where a.serialno = b.serialno;
或union
myCon.Open();
try
{
string str_sql = "";
str_sql = sqltext;
OdbcDataAdapter myData = new OdbcDataAdapter(str_sql, myCon);
DataSet MyDs = new DataSet();
myData.Fill(MyDs, "customerinfor");
GridView1.DataSource = MyDs.Tables["customerinfor"].DefaultView;
GridView1.DataKeyNames = new string[] { "customerno" };
GridView1.DataBind();
}
catch (Exception p)
{
}
finally
{
myCon.Close();
}一个表,我是这样写的,两个表话
myData.Fill(MyDs, "customerinfor");
能这样写么?
写了个查询返回一个集合的方法将此方法作为数据源绑定到GridView的DataSource中咯。
gridview.datasource=(集合或者table)
gridview.databind();
用这种public DataTable GetDate(string where)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "";
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable();
SqlDataReader dr = null;
cmd.CommandText = where;
cmd.Connection = cn;
using (dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
dt.Load(dr);
}
if (dt.Rows.Count != 0)
{
return dt;
}
else
{
return null;
} }返回一个DataTable 然后
this.GridView1.DataSource =GetDate;
GridView1.DataBind();
多张表查询可以SQL的 连接 left join or right join or inner join 然后弄好SQL传入到方法里就行了。