0 Hi,
That DataBind() method used in web application. I thought u want to bind the drop down list in the web application. but u want to bind the combo box in the window application. I am sending you the working code for that.
private void
Form1_Load(object sender, EventArgs e)
{
ListCustomerCode();
}
public DataSet ActiveCust() //
Create the data set
{
SqlConnection scon = new SqlConnection("server=.;database=Northwind;UID=sa;pwd=;");
scon.Open();
DataSet LCust = new DataSet();
string query = "SELECT Name,City FROM tblCity";
SqlCommand cmd = new SqlCommand(query,
scon);
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
adpt.Fill(LCust, "LostCustomer");
scon.Close();
return LCust;
}
private void ListCustomerCode()
{
DataSet Lcust = new DataSet();
Lcust = ActiveCust();
if (!object.Equals(Lcust, null))
{
comboBox1.DataSource = Lcust.Tables[0];
comboBox1.DisplayMember = "Name";
}
}
Happy Coding!!
0 Thanks Dear, I have applied the coding you sent. Can you plz check this since there are some probs.
public LostCustInfo ActiveCust() // Create the data set
{
SqlConnection scon = new SqlConnection(con.SetConnection());
scon.Open();
LostCustInfo LCust = new LostCustInfo();
string query = "SELECT cust_code,cust_name FROM CM_LOSTCUST WHERE active = 'Y'";
SqlCommand cmd = new SqlCommand(query, scon);
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
adpt.Fill(LCust, "LostCustomer");
scon.Close();
return LCust;
}
private void ListCustomerCode()
{
LostCustInfo Lcust = new LostCustInfo();
Lcust = Lcust.ActiveCust();
if (!object.Equals(Lcust, null))
{
cboCustCode.DataSource = Lcust;
cboCustCode.DataBindings; // Here there is no method like this ????????
}
}
0 Thanks for your help, I need more clarification on this, I'll put that into forum. Hope you can guide me.
0 Hi,
For binding the dropdownlist. write the method which returns all the customerid, as u want. then provide this datasource to the dropdownlist, in the page load or where u want. I am posting you the sample code for this.
dataSet = new DataSet();
dataSet = "Write the method which returnd the data."
if (!object.Equals(dataSet, null))
{
dropdownSample.DataSource = dataSet;
dropdownSample.DataBind();
}
Happy Coding!!