本文介绍了组合框中的System.Data.DataRowView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行程序时,组合框仅显示:
"System.Data.DataRowView"


When I run the program, the combo box only shows:
"System.Data.DataRowView"


private void GetSupplierName()
        {
            string query = "Select * from Supplier";
            SqlCommand cmd = new SqlCommand(query, cn);
            cmd.CommandText = query;
            //cn.Open();

            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(ds);
            cbosupplier.Items.Clear();
            cbosupplier.DisplayMember = "SupplierName";
            cbosupplier.ValueMember = "SupplierNo";
            cbosupplier.DataSource = ds.Tables[0];  
        }

推荐答案

private void GetSupplierName()

        {
         try
            {
                cbosupplier.Items.Clear();

                string query = "Select distinct SupplierName from Supplier" +
                    " order by SupplierName asc";
                SqlCommand cmd = new SqlCommand(query, cn);
                cmd.CommandText = query;
                

                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    cbosupplier.Items.Add(dr["SupplierName"].ToString());
                }
            }
            catch
            {
                MessageBox.Show("Error in Connection");
            }
           }


<Window.Resources>
  <DataTemplate x:Key="comboTemplate">
        <TextBlock Text="{Binding Path=username}" />
  </DataTemplate>
</Window.Resources>
<ComboBox Margin="18,121,24,0" Name="cmbEmail" Tag="email" TabIndex="1" ToolTip="enter the email you signed up with here" IsEditable="True" IsSynchronizedWithCurrentItem="True" ItemTemplate="{StaticResource comboTemplate}"  ItemsSource="{Binding}" Height="23" VerticalAlignment="Top" Style="{DynamicResource cmbBoxerrors}">
            <ComboBox.Text>
                <Binding Path="username"/>
            </ComboBox.Text>
 </ComboBox>



这篇关于组合框中的System.Data.DataRowView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 02:56