Hi,
I am selecting value from one combobox and want to use its value to update the second combobox. but the error is that the second combobox is not showing any value. plz help me.
namespace ShopSoftware
{
public partial class frmSelling : Form
{
public frmSelling()
{
InitializeComponent();
}
clsConnection clsConn = new clsConnection();
SqlCommand sqlCmd = new SqlCommand();
SqlCommand sqlCmd1 = new SqlCommand();
SqlCommand sqlCmd2 = new SqlCommand();
SqlCommand sqlCmd3 = new SqlCommand();
private void frmSelling_Load(object sender, EventArgs e)
{
BindData1();
}
public void BindData1()
{
sqlCmd.Connection = clsConn.conn;
sqlCmd.CommandText = "select cPName from Product ";
sqlCmd.CommandType = CommandType.Text;
//sqlConn.Open();
clsConn.GetConnection(); //to open and close sql connection i have made class for it.
SqlDataAdapter sqlAdpt = new SqlDataAdapter();
sqlAdpt.SelectCommand = sqlCmd;
sqlAdpt.SelectCommand.ExecuteNonQuery();
DataSet ds = new DataSet();
sqlAdpt.Fill(ds);
sqlCmd.ExecuteNonQuery();
clsConn.GetConnection();
cbPName.DisplayMember = "cPName";
cbPName.ValueMember = "iSrNo";
cbPName.DataSource = ds.Tables[0];
cbPName.Enabled = true;
}
private void cbBName_ValueMemberChanged(object sender, EventArgs e)
{
clsConn.GetConnection();
sqlCmd2.CommandText = "select iBno from Product where cPName='" + cbPName.SelectedText + "'";
sqlCmd2.CommandType = CommandType.Text;
sqlCmd2.Connection = clsConn.conn;
SqlDataAdapter sqladpt = new SqlDataAdapter();
sqladpt.SelectCommand = sqlCmd2;
int j = 0;
DataTable dt = new DataTable();
sqladpt.Fill(dt);
SqlDataReader reader = sqlCmd2.ExecuteReader();
while (reader.Read())
{
if (!string.IsNullOrEmpty(reader["iBno"].ToString()))
{
j = Convert.ToInt32(reader["iBno"].ToString());
}
}
reader.Close();
sqlCmd.Connection = clsConn.conn;
sqlCmd.CommandText = "select cBrandName from brandName where iBno =" + j ;
sqlCmd.CommandType = CommandType.Text;
cbBName.Items.Clear();
SqlDataReader dr = sqlCmd.ExecuteReader();
while (dr.Read())
{
cbBName.Items.Add( dr["cBrandName"]);
}
clsConn.GetConnection();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}