首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >System.Data.DataRowView?

System.Data.DataRowView?
EN

Stack Overflow用户
提问于 2016-02-10 21:16:25
回答 1查看 48关注 0票数 0

我在我的项目中有7个comboboxes,我使用comboboxs从数据库中选择数据。第一个combobox运行正常,但其他combobox显示如下:

System.Data.DataRowView

我能做些什么来解决这个错误这是comboboxes的代码

代码语言:javascript
运行
复制
 private void client_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = "Data Source=.;Initial Catalog=SCP_DB;Integrated Security=True";
        con.Open();
        string query = "select  Operation_Type from Operations_Types; select Payment_Types from Payment_Type; select Property_Types from Property_Type; select City from Flats; select Section from Flats; select Block from Flats; select Street from Flats";
        SqlDataAdapter da = new SqlDataAdapter(query, con);
        da.TableMappings.Add("Table", "Operations_Types");
        da.TableMappings.Add("Table1", "Payment_Type");
        da.TableMappings.Add("Table2", "Property_Type");
        da.TableMappings.Add("Table3", "Flats");
        da.TableMappings.Add("Table4", "Flats");
        da.TableMappings.Add("Table5", "Flats");
        da.TableMappings.Add("Table6", "Flats");
        DataSet ds = new DataSet();

        da.Fill(ds, "Operations_Types");
        comboOpType.DisplayMember = "Operation_Type";
        comboOpType.ValueMember = "Operation_Type";
        comboOpType.DataSource = ds.Tables["Operations_Types"];

        da.Fill(ds, "Payment_Type");
        comboPayType.DisplayMember = "Payment_Types";
        comboPayType.ValueMember = "Payment_Types";
        comboPayType.DataSource = ds.Tables["Payment_Type"];

        da.Fill(ds, "Property_Type");
        comboProType.DisplayMember = "Property_Types";
        comboProType.ValueMember = "Property_Types";
        comboProType.DataSource = ds.Tables["Property_Type"];

        da.Fill(ds, "Flats");
        comboCity.DisplayMember = "City";
        comboCity.ValueMember = "City";
        comboCity.DataSource = ds.Tables["Flats"];

        da.Fill(ds, "Flats");
        comboSection.DisplayMember = "Section";
        comboSection.ValueMember = "Section";
        comboSection.DataSource = ds.Tables["Flats"];

        da.Fill(ds, "Flats");
        comboBlock.DisplayMember = "Block";
        comboBlock.ValueMember = "Block";
        comboBlock.DataSource = ds.Tables["Flats"];

        da.Fill(ds, "Flats");
        comboStreet.DisplayMember = "Street";
        comboStreet.ValueMember = "Street";
        comboStreet.DataSource = ds.Tables["Flats"];

        SqlCommand cmd = new SqlCommand(query, con);
        cmd.ExecuteNonQuery();
        con.Close();


    }
EN

回答 1

Stack Overflow用户

发布于 2016-02-10 21:23:38

应该只填充DataSet一次,SqlDataAdapter会处理它包含多个结果集的情况。您可以在以后为它们命名:

代码语言:javascript
运行
复制
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds);
ds.Tables[0].TableName = "Operations_Types";
ds.Tables[1].TableName = "Property_Type";
// ...
comboOpType.DisplayMember = "Operation_Type";
comboOpType.ValueMember = "Operation_Type";
comboOpType.DataSource = ds.Tables["Operations_Types"];
comboPayType.DisplayMember = "Payment_Types";
comboPayType.ValueMember = "Payment_Types";
comboPayType.DataSource = ds.Tables["Payment_Type"];
// ...

否则,Fill将在每次连续调用时附加所有记录和表。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35316332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档