查询以从differents表中选择列 [英] query for selecting columns from differents tables

查看:74
本文介绍了查询以从differents表中选择列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我..需要帮助...如何从不同的表中选择不同的列,这些列的值将在datagridview中集中显示...通过查询..等待回复

plz help me i m begnner ..need help...how to select different columns from differnt tables and values of these columns show in datagridview collectively ......through query..waiting for reply

推荐答案

请参见 [ ^ ]线程.


请参阅此初学者指南,以 ^ ],它可以
See this beginner guide to SQL[^], it can help you out.


您可以为此使用Query with JOINS.示例代码如下:

You can use Query with JOINS for this purpose. Sample code is here below:

string constr = "Data Source=.\\SQLEXPRESS; database=Library; Persist Security Info=False; Integrated Security=true;";
      using (SqlConnection con = new SqlConnection(constr))
      {
          cmd1 = con.CreateCommand();
          cmd1 = new SqlCommand("Select B.BookName, P.Publication from Books B Inner Join Publication P on B.PublicationCode = P.PublicationCode");
                cmd1.Connection = con;

                ds = new DataSet();
                adp = new SqlDataAdapter(cmd1);
                adp.Fill(ds, "Books");

                dataGridView1.DataSource = ds.Tables["Books"].DefaultView;
            }





希望对您有用.





Hope this will be useful for you.


这篇关于查询以从differents表中选择列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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