dataset 多表查询

      string citysql = "select * from soncity;select * from partytype";
        ds= DbHelperSQL.Query(citysql);
        s1.DataSource = ds.Tables[0].DefaultView;
        s1.DataTextField = "sonname";
        s1.DataBind();
        s2.DataSource = ds.Tables[1].DefaultView;
         s2.DataTextField = "partytypename";
         s2.DataBind();

 

 

在DbHelperSQL类中的Query方法

   /// <summary>
    /// 执行查询语句,返回DataSet
    /// </summary>
    /// <param name="SQLString">查询语句</param>
    /// <returns>DataSet</returns>
    public static DataSet Query(string SQLString)
    {
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            DataSet ds = new DataSet();
            try
            {
                connection.Open();
                SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
                command.Fill(ds, "ds");
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw new Exception(ex.Message);
            }
            return ds;
        }
    }

 

posted @ 2010-01-11 11:30  liuwei0214  阅读(664)  评论(0编辑  收藏  举报