System.Data.DataRowView?

本文关键字:DataRowView Data System | 更新日期: 2023-09-27 18:34:11

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

System.Data.DataRowView

我该怎么做才能解决此错误,这是comboboxes的代码?

 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();

    }

System.Data.DataRowView?

您应该只填写一次DataSetSqlDataAdapter处理它包含多个结果集的情况。之后您可以给他们起名字:

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将在每次连续调用时附加所有记录和表。