是否有可能在不使用UNION或INNER JOIN的情况下在同一个转发器中生成2个sql staments [英] Is it possible 2 make 2 sql staments in the same repeater without use UNION or INNER JOIN

查看:77
本文介绍了是否有可能在不使用UNION或INNER JOIN的情况下在同一个转发器中生成2个sql staments的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个中继器和2个桌子,我想同时评估两个表格,但不要将它们融合在一起。



当我将数据绑定到转发器时,我可以在代码隐藏中执行吗?



 SqlConnection conn =  new  SqlConnection(); 
conn.ConnectionString = ConfigurationManager.ConnectionStrings [ ConnectionString]。ToString();

SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = @ SELECT * FROM frugt ???我可以选择2吗?

ORDER BY类型
;

conn.Open();
DataTable visProdukter = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(visProdukter);
cmd.ExecuteNonQuery();
conn.Close();
VisProdukt.DataSource = visProdukter;
VisProdukt.DataBind();





/ Tina

解决方案

< blockquote>我建​​议将转发器的标题更改为水果和蔬菜的通用名称

如productid,produtname,varedi

然后您的选择语句将是:

  SELECT  frugt_id  AS  Product_id,frugt_navn  AS  ProductName,vaerdi  AS  vaerdi, FROM  frugt  UNION   SELECT  groent_id  AS  ProductID,groent_navn  AS  ProductName,groent_vaerdi  AS  Varedi  FROM  groent 



然后你的转发器中没有0值。

希望它有帮助


< BLOCKQUOTE>是。可以使用 DataReader DataAdapter


写两个select语句
详情请参阅此处,

针对SQL Server执行多个SQL语句 [ ^ ]


Hi
I have one repeater and 2 tables, and I want to eval the two tabels at the same time but without melting them together.

Could I do it in the codebehind, when I bind the data to the repeater??

SqlConnection conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandText = @"SELECT * FROM frugt??? Can I have 2 select here?
 
ORDER BY Type";

            conn.Open();
            DataTable visProdukter = new DataTable();
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            adapter.Fill(visProdukter);
            cmd.ExecuteNonQuery();
            conn.Close();
            VisProdukt.DataSource = visProdukter;
            VisProdukt.DataBind();



/Tina

解决方案

I Suggest to change repeater's header to general name for fruit and vegetable
like productid, produtname, varedi
then your select statement will be:

SELECT  frugt_id AS Product_id, frugt_navn AS ProductName, vaerdi AS vaerdi, FROM frugt UNION SELECT groent_id AS ProductID, groent_navn AS ProductName, groent_vaerdi AS Varedi FROM groent


then you will not have 0 value in your repeater.
Hope it helps


Yes. It is possible to write two select statements using DataReader and DataAdapter

Refer here for more details,
Executing multiple SQL statements as one against SQL Server[^]


这篇关于是否有可能在不使用UNION或INNER JOIN的情况下在同一个转发器中生成2个sql staments的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆