i have a combobox and i want to save the combobox item in database but the problem is that when i m not choosing any item them then error is coming of null reference.

and the other problem is that when i type any text on combobox then this also gone save and next time when form load then this shows on combo box item.

use:

if(this.comboBox1.SelectedIndex > -1)
{
    this.comboBox1.Selecteditem.ToString();
    //or:
    this.comboBox1.Text;
    //or:
    this.comboBox1.GetItemText(this.comboBox1.SelectedItem);
}

one of these it should get the selected item

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.