1
Reply

comboBox problem

roi kruv

roi kruv

Jul 31 2011 4:27 PM
1.2k

int apartmentType = 0;

if (comboBox2.Text == "upGraded")
    apartmentType = 4;

dataConnection.Open();

try
{
SqlCommand cmd = dataConnection.CreateCommand();
cmd.CommandText = "INSERT INTO tblTypeInArea (typeNum,appNum,areaName) VALUES (@typeNum,@appNum,@areaName)";
cmd.Parameters.Add("@typeNum", SqlDbType.Int).Value = apartmentType;
cmd.Parameters.Add("@appNum", SqlDbType.Int).Value = applicationNum;
cmd.Parameters.Add("@areaName", SqlDbType.NVarChar, 15).Value = comboBox1.Text;
}

this code is working fine, however when i bind the comboBox (comboBox2 in this case) to the dataBase using the dataSource it just dosent work.... i used the debugger and i found out that the variable "apartmentType" dosent get the value '4' like he should...
but when the comboBox is not bound to the dataBase it's working fine and the variable "apartmentType" get's the value '4'...
i tried to do severel things like:

if(comboBox2.SelectedText.Equals("upGraded")) or
if(comboBox2.SelectedValue.Equals("upGraded")) or
if(comboBox2.SelectedItem.Equals("upGraded")) or
if(comboBox2.SelectedText == "upGraded")

but non of that worked....

can someone please help me???


Answers (1)