在一个C#窗体中需要同时查询SQL数据库里的两个表,UseInfo和SelfRoom,以下是我写的代码,该如何更改?
public partial class SearchUseInfo,SearchSelfRoom : Form
    {
        public SearchUseInfo()
        {
            InitializeComponent();
        }
        public SearchSelfRoom()
        {
            InitializeComponent();
        }
        UseInfoService uis = new UseInfoService();
        SelfRoomService uis = new SelfRoomService();
    }
多谢各位了。

解决方案 »

  1.   

    数据库我连接了,如果只查询UseInfo这张表我可以实现并将信息导入到窗体,但要查询两个表我写的代码就老出错。。
      

  2.   

    两表总如果有主外键关系就按照其关系列去查如果没有的话你不是直接查
    select 列1,列2,、、、 from  表1,表2 where 条件然后在c#里面建立一个拥有两表所有列的实体类然后就读取数据,进行出来,就直接出来这个实体类就ok了
      

  3.   

    分开还是在一起
    分开以个成功了,下一个也可以啊
    是不是要Left Join
    您写全点,要不大火都在猜
      

  4.   

    DataSet里增加两个Adapter,方法直接调用。表参考如下。不过LZ还是要先看下基础资料SqlCommand cmd = this.Connection.CreateCommand();
                        cmd.CommandTimeout = 0;                    cmd.CommandText = "fas.usp_VochrSelect";
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@AdmCompanyID", SqlDbType.VarChar)).Value = item.AdmCompanyIDList;
    this.Adapter.SelectCommand = cmd;
                        this.Adapter.TableMappings.Clear();
                        this.Adapter.TableMappings.Add("Table", "VochrTempHead");
                        this.Adapter.TableMappings.Add("Table1", "VochrTempDetail");
                        this.Adapter.Fill(ds);
      

  5.   


      public SearchUseInfo()
      {
          InitializeComponent();
      }  public SearchSelfRoom()
      {
           InitializeComponent();
      }
    这2个方法我比较费解!
    c#中有这种写法吗 !
      

  6.   

    select u.*,s.* from UseInfo as u ,SelfRoom as s
      

  7.   

    最好封装成一个数据库操作类 DbClass里面自己重新实现一下相应的方法若2帐表没在同一个数据库文件,需要打开关闭连接2次数据库操作若在同一个数据库文件内;只需打开连接一次读取相应的内容,放入DataTable中(或DataSet)剩下操作就是检索数据的操作了,简单化啦