I am trying to get data from database into ComboBox i don't know where is the mistake in my code. When i run my code which is given below ComboBox show Empty :(
public partial class InstallInfo : Form
{
private SqlConnection xSqlConnection;
private SqlCommand xSqlCommand;
private SqlDataReader xSqlDataReader;
public InstallInfo()
{
InitializeComponent();
}
private void xcbFlatNo_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void InstallInfo_Load(object sender, EventArgs e)
{
try
{
xSqlConnection = new SqlConnection("Data Source=WaQaS-PC;Initial Catalog=BookingSystem;User ID=sa;Password=123");
xSqlConnection.Open();
}
catch (Exception ex)
{
MessageBox.Show("" + ex);
}
xSqlCommand = new SqlCommand("SELECT Pno FROM Unit1_Table where PStatus = 'Availible'", xSqlConnection);
xSqlDataReader = xSqlCommand.ExecuteReader();
bindingSource.DataSource = xSqlDataReader;
if (xSqlDataReader != null)
{
while (xSqlDataReader.Read())
{
xcbFlatNo.Items.Add(bindingSource.DataSource);
}
}
//xcbFlatNo.SelectedIndex = 0;
}
}