Dorothy

Dorothy

  • NA
  • 10
  • 0

Help with dropdown list

Nov 2 2006 6:49 AM

In my DB I have a table dept table (see below) and in my application I have a form where a user has to add his info and chose a dept from which he works for. It works fine with the Id’s. Problem is that in my employee table I have “DeptID” as a foreign key, and it doesn’t make sense for a user to click the dropdown and see 1,2,3 etc…rather I want a user to see “IT, Accounting etc..” (of which I can populate the dropdown by selecting the DeptName), problem comes when I have to insert the info into the employee table.  For example when the user selected IT from the dropdown I must insert 1 in my employee table bcoz IT =1 

  DeptID

DeptName

 1

IT

  2

Accounting

 

EmpID

DeptID

Name

Surname

001

2

Dorothy

Ntombela

002

1

Dorothy

Maseko

 Part of the code looks like this:

string cat = "Select DeptId from Department Where DeptName = '" + cboDept.Text + "' ";

int hello = Convert.ToInt32(cat);

command.CommandText = "Insert into Employee(EmpId, DeptId, Name, Surname)  Values ('" + num + "', '" + hello + "' , '" + txtname.text + "', '" + txtSurname.text  "') " ;
Error : "input string was not in a correct format"

Someone please help


Answers (3)