In overall the parameter names in the SQL statement do not match the ones you use in your program. As already said by others, you cannot have spaces between the name and the @.
So have a try with something like:
public int InsertObject(int objectID, string name, string typeObject,int number,string typeUnit)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=anbraProject;Integrated Security=True");
SqlCommand com = new SqlCommand();
com.CommandType = CommandType.Text;
com.CommandText = @"
INSERT INTO Objecttbl(objID, name, typeObj, num, typeUnit)
VALUES (@objID,
@name,
( SELECT typeID
FROM typeObjtbl
WHERE nameType = @nametype),
@num,
( SELECT typeUnitID
FROM typeUnit
WHERE nameUnit = @nameUnit)
)";
com.Connection = con;
com.Parameters.AddWithValue("@objID", objectID);
com.Parameters.AddWithValue("@name", name);
com.Parameters.AddWithValue("@nametype", ???);
com.Parameters.AddWithValue("@nameUnit", ???);
con.Open();
int Result = com.ExecuteNonQuery();
con.Close();
return Result;
}
I marked the two parameter values with question marks since I'm not able to say what values you want to use for the parameters. The point is you have to define a value that you want to use in the querying part for tables
typeObjtbl
and
typeUnit