Hi Prasunjeet,
I have created a sample that full fill your requirement.
Namespace
using System.Configuration;
using System.Data.SqlClient;
Code
private void Form1_Load_1(object sender, EventArgs e)
{
string countryQuery = "SELECT CountryID,CountryName FROM Country";
this.cbCountry.DisplayMember = "CountryName";
this.cbCountry.ValueMember = "CountryID";
this.cbCountry.DataSource = this.PopulateComboBox(countryQuery);
string stateQuery = "SELECT StateId,StateName FROM States";
this.cbState.DisplayMember = "StateName";
this.cbState.ValueMember = "StateId";
this.cbState.DataSource = this.PopulateComboBox(stateQuery);
}
private DataTable PopulateComboBox(string sqlQuery)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection conn = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(sqlQuery, conn))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
}
}
Screenshot
Hope this will help you.