我想在我的存储过程中用名称填充我的组合框。用存储过程中的数据填充组合框
public frmAddEdit(Book book, Author author)
{
_book = book;
_author = author;
_dataAccess = DataAccess.GetInstance;
_dataAccess.SetConnectionString(_dataAccess.GetServerConnectionString());
ComboFill();
InitializeComponent();
}
这是我的负荷形式
public void AddEditBook_Load(object sender, EventArgs e)
{
txtTitle.Text = _book.Title;
//comboBox1.DataSource = _book.FullName;
//comboBox1.ValueMember = "AuthorId";
//comboBox1.DisplayMember = "FullName";
ComboFill();
//txtAuthor.Text = _author.FullName;
//txtAdd.Text = book.Title;
}
我的组合框
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
DataRowView view = comboBox1.SelectedItem as DataRowView;
string fullName = view["FullName"].ToString();
}
东西,我在网上看到试了一下。
public void ComboFill()
{
DataRow dr;
DataTable dt = new DataTable();
dr = dt.NewRow();
// dr.ItemArray = new object[] { 0, "Select Author" };
dt.Rows.InsertAt(dr, 0);
comboBox1.DataSource = _book.FullName;
comboBox1.ValueMember = "AuthorId";
comboBox1.DisplayMember = "FullName";
}
为什么你做复杂的时候,你可以在一个简单的方法做到这一点? –
输入'System.Windows.Forms.ComboBox'作为没有名为'ValueMember'或'DisplayMember'的属性。 –
那么,你的问题是什么?你有什么错误?有什么问题? – Pikoh