我想在我的存儲過程中用名稱填充我的組合框。用存儲過程中的數據填充組合框
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