The error is
Conversion failed when converting the nvarchar value 'FMCS17002' to data type int
So you don't want a string (what
SelectedValue
already is in your case) but an integer. At least one of the database fields you are trying to set has the type
int
and the string value "FMCS17002" can't be converted to an integer.
So you have to change the database to use strings (
NVARCHAR
) for the corresponding fields or change the combo boxes to contain only integers (or strings representing valid integers so that they can be converted).
[EDIT]
The question has been changed after posting my solution:
Quote:
I have two tables, tbl1 have primary key with string, tbl2 have foreign key to that primary key ,when I try to insert into tbl2 value from combobox.Selected value
You have to query the ID from tbl1 first using the corresponding combo box string:
SELECT id FROM tbl1 WHERE name=selected_value
and pass the returned ID as parameter to the
INSERT
command.
[/EDIT]